How to avoid 429 error when using grequests?

452 Views Asked by At

I want to make a parser using "grequests", but as expected, due to many requests, i get an error 429.

import grequests


sites = [f"https://fantlab.ru/work{i}" for i in range(1, 10)]

response = (grequests.get(url, timeout=5)  for url in sites)
resp = grequests.map(response)

print(resp)
[<Response [200]>, <Response [200]>, <Response [200]>, <Response [404]>, <Response [429]>...]
1

There are 1 best solutions below

2
Jaffa On BEST ANSWER

A 429 (Too many requests) status code is returned when you are sending too many requests. You could try showing down the requests (using time.sleep(n) from the time module, or see if the owner of the server can increase your quota.