【问题标题】:how to fix "Exception has occurred: SSLError HTTPSConnectionPool" in VS Code environment如何在 VS Code 环境中修复“发生异常:SSLError HTTPSConnectionPool”
【发布时间】:2022-01-25 14:44:08
【问题描述】:

我尝试使用 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'))

【问题讨论】:

    标签: python windows ssl error-handling


    【解决方案1】:

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

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

    requests 为 HTTPS 请求验证 SSL 证书,就像 Web 浏览器一样。默认开启 SSL 验证,requests 无法验证证书时会抛出 SSLError。

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

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

    【讨论】:

    • 虽然这段代码 sn-p 可以解决问题,including an explanation 确实有助于提高您的帖子质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因。
    猜你喜欢
    • 2021-05-06
    • 2022-08-18
    • 1970-01-01
    • 2019-11-25
    • 2015-12-12
    • 1970-01-01
    • 2014-06-13
    • 2020-04-28
    • 1970-01-01
    相关资源
    最近更新 更多