I\'m working with a process which is basically as follows:
I do not know the exact reason for the observed behavior with .map()
. However, using the .imap()
function with size=1
always returned a 'Response 200' for my few minutes testing. Here is the code snipet:
rs = (grequests.get(u) for u in [BASE.format(t) for t in tickers])
rsm_iterator = grequests.imap(rs, exception_handler=exception_handler, size=1)
rsm_list = [r for r in rsm_iterator]
print(rsm_list)
And if you don't want to wait for all requests to finish before working on their answers, you can do this like so:
rs = (grequests.get(u) for u in [BASE.format(t) for t in tickers])
rsm_iterator = grequests.imap(rs, exception_handler=exception_handler, size=1)
for r in rsm_iterator:
print(r)
You are just sending requests too fast. As grequests
is an async lib, all of these requests are almost sent simultaneously. They are too many.
You just need to limit the concurrent tasks by grequests.map(rs, size=your_choice)
, I have tested grequests.map(rs, size=10)
and it works well.