【发布时间】:2019-03-27 09:11:11
【问题描述】:
大家好,我在使用 SSL 和 python 时遇到了问题。 我有一个带有请求的 f5 API 脚本,它运行良好。 我做了另一个 API 脚本。在另一台机器(一些我无法提供名称的 VPN 系统)上尝试使用 requests 包,因为我的带有 requests 包的 python API 脚本不起作用。 我知道当我尝试接近另一台机器的 API 时问题就开始了,因为我遇到的问题是在 2 台机器上。在另一台机器上,我故意这样做是为了看看这是否是我的问题(遗憾的是我是对的)。
有效的脚本示例:
def f5_ltm_01_active_status():
response = requests.get("https://<ip-address>/mgmt/tm/cm/device/ver=12.1.3.4", auth=("user","password"),verify=False)
try:
json_response = response.json()
if json_response["items"][0]['hostname']:
return_str = "%s is %s" %(json_response["items"][0]['hostname'],json_response["items"][0]['failoverState'])
else:
return_str = "Wrong value in JSON"
except:
return_str = "Something went wrong , please check the code "
finally:
return return_str
Python返回的错误是:
raise SSLError(e, request=request) requests.exceptions.SSLError:
HTTPSConnectionPool(host='ip-address-of-f5', port=443): Max retries
exceeded
with url: /mgmt/tm/cm/device?ver=12.1.3.4 (Caused by SSLError("Can't
connect
to HTTPS URL because the SSL module is not available."))
如果我在调试模式下运行脚本,它可以工作。
我使用的是 Windows 10
我正在使用 Python v3.7.2
我尝试做的另一件事:
在 Stackoverflow 中寻找答案
查看 Google 以尝试获得答案
擦除 Pycharm 并重新安装
擦除 python 并重新安装
擦除请求包和 urllibs3 包并重新安装
安装 open-ssl - pyopenssl 包
我真的很想知道它是如何以及为什么会发生的 但主要是如何解决它
【问题讨论】: