gpt4 book ai didi

python - 如何在 VS Code 环境中修复 "Exception has occurred: SSLError HTTPSConnectionPool"

转载 作者:行者123 更新时间:2023-12-04 22:36:00 28 4
gpt4 key购买 nike

我尝试使用 python 请求库,但出现此错误我大部分时间在 Windows 10 中使用 psiphon VPN调用 requests.get('[API URL]')

后出现以下错误
Exception has occurred: SSLError
HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /user (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)')))

During handling of the above exception, another exception occurred:


During handling of the above exception, another exception occurred:

File "C:\Users\Hessam\Desktop\QWE.py", line 3, in <module>
r = requests.get('https://api.github.com/user', auth=('user', 'pass'))

最佳答案

您应该尝试将 verify=False 添加到您的请求中:

import requests
r = requests.get('https://api.github.com/user', verify=False)

requests 验证 HTTPS 请求的 SSL 证书,就像网络浏览器一样。默认情况下,启用 SSL 验证,如果无法验证证书,requests 将抛出 SSLError。

在您的具体情况下,您的 VPN 上的 SSL 证书很可能有问题。

请注意,当 verify 设置为 False 时,requests 将接受服务器提供的任何 TLS 证书,并将忽略主机名不匹配和/或过期的证书,这将使您的应用程序容易受到中间人 (MitM) 攻击。将 verify 设置为 False 可能在本地开发或测试期间有用。

关于python - 如何在 VS Code 环境中修复 "Exception has occurred: SSLError HTTPSConnectionPool",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70481851/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com