当前位置: 移动技术网 > IT编程>脚本编程>Python > 使用requests爬取报错“Max retries exceeded with url“的解决方法

使用requests爬取报错“Max retries exceeded with url“的解决方法

2020年07月30日  | 移动技术网IT编程  | 我要评论
某次在写爬虫时,运行之后报错requests.exceptions.ProxyError:HTTPSConnectionPool(host=‘xxx.xxx.xxx’, port=443):Max retries exceeded with url: xxxxxxx (Caused by ProxyError(‘Cannot connect to proxy.’, NewConnectionError(’<urllib3.connection.HTTPSConnection object at

某次在写爬虫时,运行之后报错

requests.exceptions.ProxyError:
HTTPSConnectionPool(host=‘xxx.xxx.xxx’, port=443):
Max retries exceeded with url: xxxxxxx (Caused by ProxyError
(‘Cannot connect to proxy.’, NewConnectionError(’<urllib3.connection.HTTPSConnection object at 0x000001EF209B1D30>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。’)))

原因:

  1. http连接太多没有关闭导致的
  2. 可能是访问过于频繁,使用IP代理即可

使用IP代理参考以下文章
Python爬虫避坑IP代理教程避坑(reuqests和selenium的ip代理)

解决办法

1、增加重试连接次数
requests.DEFAULT_RETRIES = 5
s = requests.session()
2、关闭多余的连接
s.keep_alive = False

requests使用了urllib3库,默认的http connection是keep-alive的,requests设置False关闭。

如果对大家有帮助,可以点赞关注和收藏一下哦,谢谢各位!

博主更多博客文章

本文地址:https://blog.csdn.net/llllllkkkkkooooo/article/details/107637980

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网