我使用RiotWatcher来使用python访问riot。由于我使用一个开发键执行了很多查询,所以我试图注意429个错误,表示超出了允许的查询速率。
在进行一些测试时,RiotWatcher似乎包含了一个与文档一致的自动RetryAfter。如果超出了限制,则一旦查询可用,就会暂停并重新启动。
我尝试了文档中给出的以下示例,但它不像我想象的那样有效。
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在错误429时,请求暂停并在时间过去后继续,但我从未收到错误消息。
您知道是否有可能知道观察者由于429错误而暂停的时间吗?谢谢!
发布于 2022-03-16 13:29:06
在研究Riot包代码,特别是BasicRateLimiter.py文件时,我发现了以下代码,第49行:
LOG.debug(
"waiting for %s seconds due to %s limit...",
to_wait.total_seconds(),
wait_until[1],
)因此,要获取有关暂停以限制请求和剩余时间的信息,只需查看日志中的调试消息。
发布于 2022-03-15 15:18:59
根据docs https://riot-watcher.readthedocs.io/en/latest/riotwatcher/Riot/index.html,在创建观察者实例时,可以指定要使用的速率限制器。它默认为Handlers.RateLimit.BasicRateLimiter,因此您可能应该将其设置为您自己的子类,或者它也可能与None一起工作。默认速率限制器将拦截429个错误,并在没有看到错误的情况下进行重试。
https://stackoverflow.com/questions/71484648
复制相似问题