Gspread配额超过,错误429 - Python



我正在做一个机器人把一个网站的结果与谷歌表API表。但是我收到的错误是429。我看到一些人说要定个时间。sleep来处理它,但我不确定我可以把它放在我的代码中。请问,有人能帮忙吗?我是Python的新手。

from googleapiclient.discovery import build
from google.oauth2 import service_account
from oauth2client.service_account import ServiceAccountCredentials
import gspread
scope = ['https://www.googleapis.com/auth/spreadsheets', "https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name(r'C:UsersCamilaPython-projectsavon-chave-sheets.json', scope)
client = gspread.authorize(creds)
result = client.open("Dados_faturados_dia_avon").worksheet("dadosfaturados")
i = 1
while result.cell(i, 1).value != "":
i = i + 1

result.update_cell(i,1, valores)

错误:

APIError: {'code': 429, 'message': "Quota exceeded for quota metric 'Read requests' and limit 'Read requests per minute per user' of service 'sheets.googleapis.com' for consumer 'project_number:532510513093'.", 'status': 'RESOURCE_EXHAUSTED', 'details': [{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'RATE_LIMIT_EXCEEDED', 'domain': 'googleapis.com', 'metadata': {'quota_limit': 'ReadRequestsPerMinutePerUser', 'consumer': 'projects/532510513093', 'quota_metric': 'sheets.googleapis.com/read_requests', 'service': 'sheets.googleapis.com'}}]}

在您的代码中,您需要捕获错误,然后重试。

我不是一个python开发人员,但像这样的东西应该让你开始。

from googleapiclient.errors import HttpError
try:
result.update_cell(i,1, valores)
except HttpError as err:
# If the error is a rate limit or connection error,
# wait and try again.
if err.resp.status in [403, 429, 500, 503]:
time.sleep(5)
else: raise

相关内容

  • 没有找到相关文章

最新更新