解决报错requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘xxx’, port=443): Max retries exceeded with url 使用requests时出错
解决报错requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘xxx’, port=443): Max retries exceeded with url 使用requests时出错
一、先检查一下自己的库中是否装了下面三个库
certifi、cryptography、pyOpenSSL
# 没有的话请依次安装
pip install certifi
pip install cryptography
pip install pyOpenSSL
二、请在网页请求中加入:verify=False
这个的含义是: requests设置移除SSL认证
response = requests.get(url, headers=headers,verify=False)
print(response)
# 但是可能会出现 InsecureRequestWarning 警告,
# 虽然不影响代码采集但是看着不舒服,可以加上下面两行:
import urllib3
urllib3.disable_warnings()
三、访问频繁
1、在代码中加入延迟 time.sleep(3)
2、更换IP
3、更换使用随机的UA
4、网络问题,更换网络或者使用手机流量
四、连接数过多
如果requests连接数很多,那么在请求中避免使用持久连接
可以在请求头headers中加入
headers = {'Connection': 'close'}
requests.adapters.DEFAULT_RETRIES = 5
五、可能出现的别的原因
1、设置session
import requests
session = requests.session()
...
response = session.get(url, headers=headers,verify=False)
print(response)
2、requests请求网页时可能会请求不到,重试,加入try…except…语句
try:
response = session.get(url, headers=headers,verify=False)
except:
response = session.get(url, headers=headers,verify=False)
print(response)
- HTTPSConnectionPool ConnectionError exceptions requests hosthttpsconnectionpool connectionerror exceptions requests sslerror httpsconnectionpool exceptions httpsconnectionpool exceptions proxyerror requests httpsconnectionpool软件站exceptions requests host verification key requested 网段request host arp quot bindexception exception requested exceptions requests sslerror解决方案 exceptions proxyerror requests方法 connectionerror