python - 使用带有请求的 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 新手。谁能帮我摆脱错误?
解决方案
推荐阅读
- c++ - 如何在参数和返回类型上使用匹配的 const 修饰符编写函数?
- pandas - 从一系列列表中提取第一项并用作索引
- kubernetes - Kubernetes 查找 pod 的日志
- excel - 在可排序/可过滤的 Excel 表中进行两种查找
- python - 在后台任务中使用多个工作人员 - Fast-API
- google-cloud-spanner - 使用 Google API 的 Python 中的 Google Cloud Spanner 合并 SQL 等效过程
- c# - 自定义 PostSharp 日志记录
- javascript - 当我在 OpenVPN 后面时,浏览器在建立 WebSocket 连接一秒后关闭并显示错误 1006
- python - Django DRF 计算字段检查
- java - 比较 Set 中的键后从 Map 中删除条目