• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
BeyondTechnology
博客园    首页    新随笔    联系   管理    订阅  订阅

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

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] 由于连接方在一段时间后没有正确答复或连接的主机没有反 应,连接尝试失败。',))

 

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

posted @ 2018-09-03 22:56  BeyondTechnology  阅读(20254)  评论(3)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3