gpt4 book ai didi

Python Google Sheets API 循环限制 429 错误

转载 作者:行者123 更新时间:2023-12-02 20:10:13 28 4
gpt4 key购买 nike

我正在运行一个 python 脚本,该脚本通过 Google 表格 API 和 Gspread 包将特定列从一个 Google 表格转移到另一个 Google 表格,但是我在推送时遇到了 429 错误新电子表格的列表。此错误与太多请求有关,但我不确定是什么让我的推送运行多次,而不是一次。我的 worksheet.update_cells(updated_values) 是否可能包含在循环中?

错误:

APIError: {
"error": {
"code": 429,
"message": "Quota exceeded for quota group 'WriteGroup' and limit 'USER-100s' of service 'sheets.googleapis.com' for consumer 'project_number:*id*'.",
"status": "RESOURCE_EXHAUSTED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developer console API key",
"url": "https://console.developers.google.com/project/*id*/apiui/credential"
}
]
}
]
}
}

代码:

# column names
print(columns) # ['date', 'b_clicks', 'b_cpc']

# store count of column names
gs_columns = []

# count columns
for i in range(0,len(columns)):
gs_columns.append(i+1)

print(gs_columns) # [1,2,3]

updated_values = []

for col_val, col_name in zip(gs_columns, columns):
worksheet_range = worksheet.range(1, col_val, 500, col_val); # [row_start, col_start, row_end, col_end]
print(type(worksheet_range))
column_data = df_full[col_name].values.tolist();
for cell, data in zip(worksheet_range, column_data):
cell.value = data
updated_values.append(cell)

worksheet.update_cells(updated_values)
print(updated_values)
print(type(updated_values))
print(len(updated_values))

打印:

['date', 'b_clicks', 'b_cpc']
[1, 2, 3]
<class 'list'>
<class 'list'>
<class 'list'>
[<Cell R1C1 1514764800000000000>, <Cell R2C1 1514851200000000000>, <Cell R3C1 1514937600000000000>....<Cell R345C3 3.21>, <Cell R346C3 3.92>]
<class 'list'>
1038

最佳答案

遇到同样的问题有没有办法我们可以按照下面的条件来限制程序比如下面在for循环中我们可以限制对api的请求数并匹配以下条件

time.sleep(10)

关于developers.google.com :

Google Sheets API has a limit of 500 requests per 100 seconds per project, and 100 requests per 100 seconds per user. Limits for reads and writes are tracked separately. There is no daily usage limit.

关于Python Google Sheets API 循环限制 429 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53765222/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com