试读部分
【爬虫 | Python】解决'Requests Max Retries Exceeded With Url in Python'报错的问题 背景 解决方案 一、普遍方案 细致方案 一、问题重述 1.错误的 URL 2.未能验证 SSL 证书 3.网络不稳定 4.发送太多请求/服务器过载 二、应对方案 1.方案一:仔细检查 URL 2.方案二:解决SSLError 3.方案三:解决网络不稳定的问题 方案A 方案B 4.方案四:超时处理服务器请求 背景 我们在写爬虫的时候,经常会遇到这样的报错信息: HTTPConnectionPool(host=‘xxx.xxx.com’, port=443): Max retries exceeded with url: /api/v2/oauth (Caused by NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x7fac5953ab70>: Failed to establish a new connection: [Errno 110] Connection timed out’)) 这里有3个重要的信息点,分别是: HTTPConnectionPool(host='xxx.xxx.com', port=443)
Max retries exceeded with url:
Connection timed out
解决方案 一、普遍方案 针对上述的问题,目前网上给出3种解决方案: 1.在Headers里添加Connection参数,使其为close,因为默认为keep-alive。 因为requests使用的http连接池在发出request后会继续保持connection处于活跃状态,而http线程池里的的线程数是有限的。当多次requ……
本文为 VIP 文章,已展示部分内容,开通 VIP 后查看全文
觉得这篇文章有帮助?
点个赞,或赞赏支持作者持续创作