我经历了很多429"太多的请求"从大量工作表下载数据时出错。具体来说,我遇到USER-100s
速率限制。
根据documentation,我尝试将quotaUser
查询参数与每个请求的随机值一起使用,以绕过用户限制并且仅受项目限制相反,这是每100秒500个请求。
但是,我对速率限制没有看到是否使用quotaUser
参数。
使用以下小测试代码段(URL
作为Sheets API端点):
def run(url, use_quota_user=False):
for i in range(200):
headers = {
'Authorization': 'Bearer %s' % ACCESS_TOKEN
}
if use_quota_user:
_url = '%s"aUser=%s' % (url, str(uuid.uuid4()))
else:
_url = url
resp = requests.get(_url, headers=headers)
if resp.status_code == 200:
pass
elif resp.status_code == 429:
print('Quota exhausted with request %d: %s' % (i, resp.json()['error']['message']))
break
else:
print('Received error, aborting: %s' % resp.json()['error']['message'])
return
def main():
print('Running without quotaUser...')
run(URL, use_quota_user=False)
time.sleep(100)
print('Running with quotaUser...')
run(URL, use_quota_user=True)
无论有没有quotaUser
我都得到(几乎)完全相同的行为:
Running without quotaUser...
Quota exhausted with request 103: Insufficient tokens for quota 'ReadGroup' and limit 'USER-100s' [...]
Running with quotaUser...
Quota exhausted with request 105: Insufficient tokens for quota 'ReadGroup' and limit 'USER-100s' [...]
我做错了吗?如何正确使用quotaUser
参数,以便我不会达到USER-100s
限制?