分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

HTTPConnectionPool(host='xx.xx.xx.xx', port=xx): Max retries exceeded with url:(Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000015A25025EB8>...))

发布时间:2023-09-06 02:13责任编辑:郭大石关键词:url

HTTPConnectionPool(host=‘xx.xx.xx.xx‘, port=xx): Max retries exceeded with url:(Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000015A25025EB8>, ‘Connection to xx.xx.xx.xx timed out. (connect timeout=10)‘))

网查说是http连接太多没有关闭导致的

解决办法:

1、增加重试连接次数

requests.adapters.DEFAULT_RETRIES = 5

2、关闭多余的连接

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

s = requests.session()

s.keep_alive = False

网搜的解决方案,我的代码在for循环里不断post url,的确是打开了很多连接没关闭。

不知道是不是这个原因,加上上述3行代码之后,代码跑完了。

除上述改动外,timeout由原来的10改为了30。

还有另外一种说法是在上述3行代码基础上再挂代理,代理设置一下proxies参数即可,不贴代码了。

不过没有尝试,可用的免费代理比较少,效率会非常低,不管有用否,不尝试了。

unfortunately,第二次再跑又报如下错误:

HTTPConnectionPool(host=‘‘xx.xx.xx.xx‘, port=xx): Max retries exceeded with url: (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x00000237EE44EF98>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反 应,连接尝试失败。‘,))

太晚了,先睡了,回头再说吧。

HTTPConnectionPool(host='xx.xx.xx.xx', port=xx): Max retries exceeded with url:(Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x0000015A25025EB8>...))

原文地址:https://www.cnblogs.com/BeyondTechnology/p/9581712.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved