呼び出してデータを取得したい ~300K API URL のリストがあります。
lst = ['url.com','url2.com']
リストをサブセット化して、5 つの URLgrequest
でリクエストを完全に処理するとします。ただし、〜 300K の完全な URL を渡すと、エラーが発生します。
Problem: url.Iam.passing.in: HTTPSConnectionPool(host='url', port=xxx): Max retries exceeded with url: url.Iam.passing.in (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x552b17550>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))
Traceback (most recent call last):
非同期呼び出しを行うためのこれまでのコード:
class Test:
def __init__(self):
self.urls = lst
def exception(self, request, exception):
print ("Problem: {}: {}".format(request.url, exception))
def async(self):
return grequests.map((grequests.get(u, stream=False) for u in self.urls), exception_handler=self.exception, size=5)
def collate_responses(self, results):
return [x.text for x in results]
test = Test()
#here we collect the results returned by the async function
results = test.async()
response_text = test.collate_responses(results)
合格したとしても、何が間違っているのかわかりませんstream=False
。
リストをバッチで渡すことができる方法はありますか?