I'm building an automated script to do some recurring search using GH search API. However I hit the "Secondary" rate limit sometimes. For referece I'm using github3.py library.
So my workaround so far is to check the rate limit before each search request like this:
for term in SEARCH_TERMS:
self.check_rate_limit()
result = gh.search_code(term)
while True:
try:
self.check_rate_limit() # it checks gh.rate_limit() if ["resources"]["search"]["remaining"] is lower (but it seems it's not being hit)
item = next(result)
# process...
time.sleep(2) # This helps a bit but I still hit the secondary rate limit
except ForbiddenError:
logging.error("(Secondary) Rate limit reached.")
time.sleep(120) # sleep 2 minutes but it continues to next iteration
except StopIteration:
break
But it never reaches the sleep condition. Instead, after the search query and while iterating the generator results, sometimes I get a github3.exceptions.ForbiddenError
because of the secondary rate limit. The probability of raising that error decreases when I force a time.sleep(2)
on each result iteration, but that doesn't seem right to me. I tried to understand more about the secondary rate limit but I couldn't find a clear explanation in the documentation. Am I missing something?