【问题标题】:How solve python requests error: "Max retries exceeded with url"如何解决 python 请求错误:“最大重试次数超出 url”
【发布时间】:2017-06-22 21:55:11
【问题描述】:

我有以下代码:

res = requests.get(url)

我使用多线程方法会出现以下错误:

ConnectionError: HTTPConnectionPool(host='bjtest.com', port=80): Max retries exceeded with url: /rest/data?method=check&test=123(原因:[Errno 104] Connection reset by peer)

我用了follow方法,还是报错:

s = requests.session()
s.keep_alive = False

res = requests.get(url, headers={'Connection': 'close'})

那么,我应该怎么做呢?

顺便说一句,url 是可以的,但它只能在内部访问,所以url 没有问题。谢谢!

【问题讨论】:

  • bjtest.com 可以访问吗?
  • @DuyNguyen 是的,但它只访问内部。

标签: python python-requests


【解决方案1】:

错误消息(诚然有点令人困惑)实际上意味着 requests 根本无法连接到您请求的 URL。

在这种情况下,这是因为您的 urlhttp://bjtest.com/rest/data?method=check&test=123,这不是一个真正的网站。

这与您提出请求的格式无关。修复您的url,它应该(大概)适合您。

【讨论】:

    【解决方案2】:

    您在 Mac 上运行脚本?我也遇到类似的问题,你可以执行 ulimit -n 来查看一次可以处理多少个文件。

    您可以使用下面的放大配置。

    resource.setrlimit(resource.RLIMIT_NOFILE, (the number you reset,resource.RLIM_INFINITY))
    

    希望能帮到你。

    my blog which associated with your problem

    【讨论】:

    • ulimit -n 结果是65536
    【解决方案3】:

    我有一个类似的案例,希望它可以为您节省一些时间:

    requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8001): Max retries exceeded with url: /enroll/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10f96ecc0>: Failed to establish a new connection: [Errno 61] Connection refused'))

    这个问题实际上很愚蠢......本地主机在端口 8001 上关闭了!重启服务器解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      • 2014-07-25
      • 1970-01-01
      • 2022-06-12
      • 1970-01-01
      • 1970-01-01
      • 2017-12-26
      相关资源
      最近更新 更多