简体   繁体   English

将gevent / greenlets与请求一起使用时获取ServerNotFoundError

[英]Getting ServerNotFoundError when using gevent/greenlets with requests

I'm trying to paralellize the retrieval of data from a remote API. 我正在尝试将远程API的数据检索并列。 The remote API doesn't have any bulk capability, so for each object I need, I have to make a separate GET request. 远程API没有任何批量功能,因此对于我需要的每个对象,我都必须发出单独的GET请求。

I've added gevent into the mix. 我已经将gevent添加到了组合中。 It works great sometimes, but if I try the same set of requests again, 50 of 100 will fail with this: 有时效果很好,但是如果我再次尝试同一组请求,则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

Any thoughts on ways to resolve this? 对解决此问题有任何想法吗? Is this a result of too many requests too quickly? 这是太多请求导致的结果吗? If so, is there an easy way to throttle the number of greenlets? 如果是这样,是否有一种简单的方法来限制绿色单元的数量?

Gevent has been known to cause some DNS issues with python-requests (which you inadvertently and incorrectly tagged) as part of this question. 众所周知,Gevent会导致与python请求有关的一些DNS问题(您无意中和错误地标记了该问题),这是该问题的一部分。 Luckily for you, we have seen this issue before and the user resolved it like so 幸运的是,我们之前已经看到过此问题,并且用户像这样解决了它

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

With that in mind, another user noted that this may already be fixed in a new version of gevent . 考虑到这一点,另一位用户指出,这可能已经在新版本的gevent中修复

Regardless if the above snippet works for you, you should probably try upgrading gevent to make sure it isn't that. 不管上面的代码片段对您是否有用,您都应该尝试升级gevent以确保它不是那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM