I use RiotWatcher to access the riot API with python. Since I do a lot of queries with a development key, I try to watch out for 429 errors indicating an overrun of the allowed query rate.
In doing some testing, it seems that RiotWatcher includes an automatic RetryAfter, which is consistent with the documentation. If the limit is exceeded, it pauses and restarts as soon as a query is available.
I tried the following example given in the documentation, but it does not work as I imagined.
try:
response = watcher.summoner.by_name(region, 'Poco')
except ApiError as err:
if err.response.status_code == 429:
print('We should retry in {} seconds.'.format(err.headers['Retry-After']))
print('this retry-after is handled by default by the RiotWatcher library')
print('future requests wait until the retry-after time passes')
elif err.response.status_code == 404:
print('Summoner with that ridiculous name not found.')
else:
raise
On error 429, the request pauses and continues after the time has elapsed, but I never get the error message.
Do you know if it is possible to know when the watcher pauses due to a 429 error? Thank you!
CodePudding user response:
According to the docs https://riot-watcher.readthedocs.io/en/latest/riotwatcher/Riot/index.html when you create the watcher instance, you can specify the rate limiter to be used. It defaults to Handlers.RateLimit.BasicRateLimiter
so you should probably set it to your own subclass, or it may also work with None. The default rate limiter will be intercepting the 429 errors and doing the retries without you ever seeing the errors.
CodePudding user response:
Exploring the Riot Watcher package code, in particular the BasicRateLimiter.py file, I found the following code, line 49:
LOG.debug(
"waiting for %s seconds due to %s limit...",
to_wait.total_seconds(),
wait_until[1],
)
So to get the information about the pause to limit requests, and the remaining time, just look at the DEBUG messages in the log.