编程语言
首页 > 编程语言> > python requests proxies 代理https 提示 HTTPSConnectionPool(host=‘***‘, port=443): Max retries 的问题解决过程

python requests proxies 代理https 提示 HTTPSConnectionPool(host=‘***‘, port=443): Max retries 的问题解决过程

作者:互联网

使用requests proxies 代理时,发现 http 代理是正常的,但是使用https的时候报:

proxy = {'https': 'https://60.174.188.15:9999'}

re = requests.get(url="https://www.baidu.com", proxies=proxy,  timeout=2)

HTTPSConnectionPool(host='***', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x000002A1DD63B1D0>, 'Connection to ******* timed out. (connect timeout=2)'))
 

开始以为是https 证书的问题或者连接过多,然后加上 verify=False 忽略证书,加上 headers={'Connection': 'close'}  不保持连接

import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
re = requests.get(url="https://www.baidu.com", proxies=proxy, headers={'Connection': 'close'}, timeout=2, verify=False)

但是加上后还是报:

HTTPSConnectionPool(host='***', port=443): Max retries exceeded with url:。。。。。

最后找了下资料才发现 requests  使用https 代理时,格式与http 一样:

proxy = {'https': 'https://60.174.188.15:9999'}  =》 proxy = {'http': 'http://60.174.188.15:9999'}

改成这样,运行正常!

标签:retries,HTTPSConnectionPool,http,python,url,proxy,https,requests,proxies
来源: https://blog.csdn.net/u011139163/article/details/117286202