2013-10-16 51 views
0

我試圖從遠程API中並行檢索數據。遠程API沒有任何批量功能,因此對於我需要的每個對象,我必須提出一個單獨的GET請求。使用gevent/greenlets請求時獲取ServerNotFoundError

我已將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 

的方式有什麼想法來解決這個問題?這是太多請求的結果嗎?如果是這樣,是否有一個簡單的方法來節制greenlet的數量?

回答

0

Gevent已知會導致一些與請求(你無意和不正確標記)的問題的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

無論上面的代碼片段適合你,你應該嘗試升級gevent以確保它不是那樣。