【问题标题】:Getting ServerNotFoundError when using gevent/greenlets with requests使用带有请求的 gevent/greenlets 时出现 ServerNotFoundError
【发布时间】:2013-10-25 02:55:13
【问题描述】:

我正在尝试并行化从远程 API 检索数据。远程 API 没有任何批量功能,因此对于我需要的每个对象,我必须发出单独的 GET 请求。

我已将 gevent 添加到组合中。有时效果很好,但如果我再次尝试同一组请求,100 个请求中的 50 个将失败:

Traceback (most recent call last):
  ...
  File "/Users/---/venv/lib/python2.7/site-packages/httplib2/__init__.py", line 1570, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/Users/---/venv/lib/python2.7/site-packages/httplib2/__init__.py", line 1317, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/Users/---/venv/lib/python2.7/site-packages/httplib2/__init__.py", line 1258, in _conn_request
    raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
ServerNotFoundError: Unable to find the server at my.remote.host

<Greenlet at 0x10c6eacd0: function_name(<Object1>, <Object2>, u'zebra', True)> failed with ServerNotFoundError

对解决此问题的方法有什么想法吗?这是因为太多请求太快的结果吗?如果是这样,有没有一种简单的方法来限制绿灯的数量?

【问题讨论】:

    标签: python gevent httplib2 greenlets


    【解决方案1】:

    已知 Gevent 会导致一些与 python-requests 相关的 DNS 问题(您无意中错误地标记了这些问题)作为此问题的一部分。幸运的是,我们之前已经看到过这个问题,用户 resolved it 也是这样

    gevent.dns.resolve_ipv4('example.com')
    # However you make your httplib2 call.
    

    考虑到这一点,另一位用户注意到这个may already be fixed in a new version of gevent。

    无论上述 sn-p 是否适合您,您都应该尝试升级 gevent 以确保它不是那样。

    【讨论】:

      猜你喜欢
      • 2014-02-01
      • 2013-11-15
      • 2017-12-20
      • 2012-05-03
      • 1970-01-01
      • 1970-01-01
      • 2020-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多