首页 > 解决方案 > 使用带有请求的 RestApi 会导致 SSL 模块不可用错误

问题描述

我正在尝试使用RestAPI我已经测试过的,C#但现在我想重写客户端以Python获得学习效果。我Visual Studio在下编码Windows

我所做的是:

import requests

class myClass:
    def __init__(self, username, password):
        self.username = username
        self.password = password

def getToken(self):
    endpoint = "https://test.com/web/service/auth/token"
    headers = {
        "username" : self.username,
        "password" : self.password,
        "environment" : "env_me",
        "grant_type" : "password",
        "Content_Type" : "application/x-www-form-urlencoded"
        }
    r = requests.post(endpoint, headers=headers)
    return print(r.json())


myObj = myClass("UN","PS")
token = myObj.getToken()
print(token)    

运行此代码给了我错误:

SSLError(MaxRetryError('HTTPSConnectionPool(host=\'test.com\', port=443): Max retries exceeded with url: /web/service/auth/token (Caused by SSLError("Can\'t connect to HTTPS URL because the SSL module is not available."))'))

因为我可以找到任何帮助,所以我试图这样做,Import ssl但这给了我错误:找不到特定的模块。from ssl import ...给了我一大堆东西可供选择,但我不知道该选择什么,因为我是 Python 新手。谁能帮我摆脱错误?

标签: pythonvisual-studiorestpython-requests

解决方案


推荐阅读