Following the following question and solution, how to reset all rows and column data uisng python gspread sheets, I have the following exact code
requests = {"requests": [{"updateCells": {"range": {"sheetId": worksheet._properties['sheetId']}, "fields": "*"}}]}
res = spreadsheet.batch_update(requests)
but I am receiving the following error
File "/root/.local/lib/python3.8/site-packages/gspread/models.py", line 1171, in batch_update data = [ File "/root/.local/lib/python3.8/site-packages/gspread/models.py", line 1172, in <listcomp> dict(vr, range=absolute_range_name(self.title, vr['range'])) TypeError: string indices must be integers
Anyone who has experienced this? and how did you resolve it?
Although, unfortunately, I cannot see your whole script in your question, from your error message, I thought that your issue might be that you are using batch_update
method in class gspread.models.Worksheet. Because in my environment, when I tested the following script, I confirmed the same error with you.
worksheet = spreadsheet.worksheet(sheetName)
requests = {"requests": [{"updateCells": {"range": {"sheetId": worksheet._properties['sheetId']}, "fields": "*"}}]}
res = worksheet.batch_update(requests)
print(res)
In this case, please use batch_update
method in class gspread.models.Spreadsheet.
In order to remove this issue, how about the following sample script?
client = gspread.authorize(credentials)
spreadsheetId = "###" # Please set Spreadsheet ID.
sheetName = "###" # Please set sheet name.
spreadsheet = client.open_by_key(spreadsheetId)
worksheet = spreadsheet.worksheet(sheetName)
requests = {"requests": [{"updateCells": {"range": {"sheetId": worksheet._properties['sheetId']}, "fields": "*"}}]}
res = spreadsheet.batch_update(requests)