正题
使用pip命令查看urllib3版本
pip list
发现版本为 1.26.9
urllib3 v1.26.9
此时如下报错,无法正常使用(使用了代理)
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='xxx.xxxxx.com', port=443): Max retries exceeded with url: /xxxxxxxxxx (Caused by ProxyError('Cannot connect to proxy.', TimeoutError('_ssl.c:980: The handshake operation timed out')))
因为我必须要走代理,所以不能在代码里通过强制不走代理的方法避免此报错
此时只需要 安装低版本urllib3 (v1.2.3)
使用pip命令安装urllib3 v1.2.3
pip3 install urllib3==1.23
修改项目requirements.txt文件中的urllib3版本号,项目没有requirements文件的忽略
urllib3~=1.2.3
再次运行,程序正常执行,但会有警告
C:\Python310\lib\site-packages\urllib3\connectionpool.py:852: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warningswarnings.warn((
直接到connectionpool.py的对应路径找到connectionpool.py打开编辑器找到852行,把警告注释
# if not conn.is_verified:
# warnings.warn((
# 'Unverified HTTPS request is being made. '
# 'Adding certificate verification is strongly advised. See: '
# 'https://urllib3.readthedocs.io/en/latest/advanced-usage.html'
# '#ssl-warnings'),
# InsecureRequestWarning)