-1

我正在使用以下 python 代码将行附加到谷歌工作表。

  KEY = "--snip--" 
  SHEET = "Sheet1"

  def update_gdoc():
     gdc = gdata.spreadsheet.service.SpreadsheetsService()
     gdc.email = gDataConstants.GDATA_USERNAME
     gdc.domain = 'mydomain.com'
     gdc.password = gDataConstants.GDATA_PASSWORD
     gdc.source = 'API User Task'
     gdc.ProgrammaticLogin()

     entry = gdata_utils.sheetByName(gdc, KEY, SHEET)
     wid = entry.id.text.split("/")[-1]

     values = ["2013", "12323", "99898"]
     keys = ["date" , "visitors", "atc"]

     map = dict(zip(keys, values))
     gdc.InsertRow(map, KEY, wid)

  update_gdoc()

我得到的错误是

Traceback (most recent call last):
  File "/Users/dapurv5/br/work/src/mobile/analytics/scripts/update_gdoc.py", line 27, in <module>
    update_gdoc()
  File "/Users/dapurv5/br/work/src/mobile/analytics/scripts/update_gdoc.py", line 25, in update_gdoc
    gdc.InsertRow(map, KEY, wid)
  File "/work/src/backend/python/gdata/spreadsheet/service.py", line 339, in InsertRow
    converter=gdata.spreadsheet.SpreadsheetsListFromString)
  File "/work/src/backend/python/gdata/service.py", line 1236, in Post
    media_source=media_source, converter=converter)
  File "/work/src/backend/python/gdata/service.py", line 1358, in PostOrPut
    'reason': server_response.reason, 'body': result_body}
gdata.service.RequestError: {'status': 400, 'body': 'We&#39;re sorry, a server error occurred. Please wait a bit and try reloading your spreadsheet.', 'reason': 'Bad Request'}

有什么我想念的吗?

4

1 回答 1

0

这是因为您尝试编写的电子表格是“旧的”。谷歌电子表格发布了一个新版本,您似乎只能写入新版本。

您可以通过查看 url 来判断它是哪种类型的电子表格:

OLD: spreadsheet/ccc?key=
NEW: spreadsheet/d?key=
于 2014-05-21T15:56:45.013 回答