作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用 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/
我是一名优秀的程序员,十分优秀!