报错原因
在使用代理进行请求时,代理只通过HTTP
请求,此时请求进行HTTPS
验证时验证失败。
两种解决方案
- 在
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"
修改本地代理,将HTTPS覆盖为HTTP请求
Windows 10下打开设置 -> 网络和Internet -> 代理,找到代理的IP和端口
proxies = { 'http': 'http://127.0.0.1:1080', 'https': 'http://127.0.0.1:1080' } res = requests.post(url, data=data, timeout=15, proxies=proxies)