I am running a python script that is taking specific columns from one Google Sheet to another Google Sheet via the Google Sheets API and Gspread package, but I am running into a 429 Error
when I am pushing a list to the new spreadsheet. This error is connected to too many requests, but I am not sure what is making my push run multiple times, rather than once. Is it possible that my worksheet.update_cells(updated_values)
is being included in the loop?
Error:
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"
}
]
}
]
}
}
Code:
# 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))
Print:
['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