简体   繁体   English

在使用 gsheet batch_update 的 python 3.8 上是否存在问题?

[英]Is there an issue on python 3.8 with gsheet batch_update?

Following the following question and solution, how to reset all rows and column data uisng python gspread sheets , I have the following exact code按照以下问题和解决方案, 如何重置所有行和列数据uisng python gspread sheet ,我有以下确切代码

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?你是怎么解决的?

Modification points:修改点:

  • 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.虽然,不幸的是,我在您的问题中看不到您的整个脚本,但从您的错误消息中,我认为您的问题可能是您在 class gspread.models.Worksheet 中使用batch_update方法。 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.在这种情况下,请使用batch_update中的 batch_update 方法。

In order to remove this issue, how about the following sample script?为了消除这个问题,下面的示例脚本怎么样?

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)
  • Please set your authorization script.请设置您的授权脚本。

Note:笔记:

  • I tested above script with python 3.8.3 and gspread 3.6.0, and I could confirm that the script worked.我用 python 3.8.3 和 gspread 3.6.0 测试了上面的脚本,我可以确认脚本有效。

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM