python爬虫 requests异常:requests.exceptions.ConnectionError: HTTPSConnectionPool Max retries exceeded

使用 requests抓取网页时会碰到如下异常:

requests.exceptions.ConnectionError: HTTPSConnectionPool Max retries exceeded

  • 原因

1.http的连接数超过最大限制,默认的情况下连接是Keep-alive的,所以这就导致了服务器保持了太多连接而不能再新建连接。
2.ip被封
3.请求过快

  • 解决

1.在header中不使用持久连接‘Connection’: ‘close’requests.adapters.DEFAULT_RETRIES = 5
2.若是请求过快,可设置time.sleep
3.使用代理ip
4.Requests请求时有时会请求不到页面,或是请求到空白的页面,超时要重试几次,使用try…except语句

猜你喜欢

转载自blog.csdn.net/xc_zhou/article/details/93379199