解决Python3 urllib3 urllib3.exceptions.maxretryerror httpsconnectionpool(host=‘xxxxx‘, port=443)

报错原因

在使用代理进行请求时,代理只通过HTTP请求,此时请求进行HTTPS验证时验证失败。

两种解决方案

  1. 1.25版本之前,请求时不会进行HTTPS验证。故可降低urllib3版本。
   1.25 (2019-04-22)
   Require and validate certificates by default when using HTTPS (Pull #1507)
pip install -U "urllib3<1.25"
  1. 修改本地代理,将HTTPS覆盖为HTTP请求

    Windows 10下打开设置 -> 网络和Internet -> 代理,找到代理的IP和端口

    proxies = &#123;
        'http': 'http://127.0.0.1:1080',
        'https': 'http://127.0.0.1:1080'
    &#125;
    res = requests.post(url, data=data, timeout=15, proxies=proxies)