Python Google 工作表 API 循环限制 429 错误
Python Google Sheets API Limit 429 Error with Loop
我正在 运行ning 一个 python 脚本,它通过以下方式将特定列从一个 Google Sheet 转移到另一个 Google Sheet Google Sheets API 和 Gspread 包,但是当我将列表推送到新电子表格时,我正在 运行 进入 429 Error
。此错误与太多请求有关,但我不确定是什么让我多次推送 运行,而不是一次。我的 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)
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.
我正在 运行ning 一个 python 脚本,它通过以下方式将特定列从一个 Google Sheet 转移到另一个 Google Sheet Google Sheets API 和 Gspread 包,但是当我将列表推送到新电子表格时,我正在 运行 进入 429 Error
。此错误与太多请求有关,但我不确定是什么让我多次推送 运行,而不是一次。我的 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)
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.