quotaUser如何工作?

时间:2017-12-20 10:25:49

标签: google-sheets-api

我经历了很多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&quotaUser=%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限制?

0 个答案:

没有答案