簡體   English   中英

將 Python 值更新為 Google 表格

[英]Update Python value to Google Sheet

我可以知道如何解決以下錯誤嗎?

我發現由於這些代碼行而發生錯誤

scope = ###
creds = Credentials.from_service_account_file("v1Timetable.json", scopes=scope)
client = gspread.authorize(creds)
google_sh = client.open("v1Timetable")
sheet1 = google_sh.get_worksheet(1)

for k in range(0, numberOfGroups):
    for l in c.GetGroups():
        if l == instance.GetStudentsGroupById(str(k + 1)):
            # info is updated here
            if(grNumber == 0):
                sheet1.update_cell(d + 1, t + 1, str(info))   # (row, col)
            if(grNumber == 1):
                sheet1.update_cell(d + 8, t + 1, str(info))   # (row, col)
            if(grNumber == 2):
                sheet1.update_cell(d + 15, t + 1, str(info))   # (row, col)
            if(grNumber == 3):
               sheet1.update_cell(d + 22, t + 1, str(info))   # (row, col)

gspread.exceptions.APIError: {'code': 429, 'message': "配額指標 'Write requests' 超出配額並限制消費者'project_number 服務'sheets.googleapis.com' 的每用戶每分鍾寫入請求數:332000645656'.", 'status': 'RESOURCE_EXHAUSTED', 'details': [{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'RATE_LIMIT_EXCEEDED', 'domain' : 'googleapis.com', 'metadata': {'service': 'sheets.googleapis.com', 'consumer': 'projects/332000645656', 'quota_limit': 'WriteRequestsPerMinutePerUser', 'quota_metric': 'sheets.googleapis .com/write_requests'}}]}

Google Sheets 有每個用戶每個時間單位的最大讀寫配額,看來你已經超過了。 看起來您可能正在一個一個地更新單元格,從而發送許多寫入請求而不是更少的大請求。 不要一次更新一個單元格的數據,而是嘗試一次更新一個單元格范圍。 假設您正在使用庫 Gspread,請參閱此處的文檔: link

可以通過將答案更新為數組來解決。

然后使用 sheet.update('A1',arr.tolist()) 將數組中的值更新到 Google 電子表格中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM