簡體   English   中英

將gevent / greenlets與請求一起使用時獲取ServerNotFoundError

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

我正在嘗試將遠程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

對解決此問題有任何想法嗎? 這是太多請求導致的結果嗎? 如果是這樣,是否有一種簡單的方法來限制綠色單元的數量?

眾所周知,Gevent會導致與python請求有關的一些DNS問題(您無意中和錯誤地標記了該問題),這是該問題的一部分。 幸運的是,我們之前已經看到過此問題,並且用戶像這樣解決了它

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

考慮到這一點,另一位用戶指出,這可能已經在新版本的gevent中修復

不管上面的代碼片段對您是否有用,您都應該嘗試升級gevent以確保它不是那樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM