2013-07-12 99 views
-1

我正在使用以下python代碼將行附加到Google工作表。從Python代碼寫入Google Spreadsheet代碼

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'} 

什麼我很想念?

+0

你會想無效該鍵... – Qix

回答

0

這是因爲您試圖編寫的電子表格是「舊」的。谷歌電子表格發佈了一個新版本,似乎只能寫入新的版本。

你可以告訴它是通過查看URL這類型的電子表格:

OLD: spreadsheet/ccc?key= 
NEW: spreadsheet/d?key= 
+0

非常有信心,你可以寫信給新老電子表格GDATA。但是有一些已知問題會使用gdata API更新新的電子表格(例如https://code.google.com/p/gdata-python-client/issues/detail?id=692) – mbrenig