Python Google表示写入工作表存在问题

时间:2017-10-08 15:12:32

标签: python google-sheets-api

我在这里https://developers.google.com/sheets/api/samples/writing关注Google API说明并遇到问题 用这个块:

PUT https://sheets.googleapis.com/v4/spreadsheets/spreadsheets/d/\
    spreadsheetId/values/sheet1!A1:D5?valueInputOption=USER_ENTERED
    values = {
    "range": "'Main'!A1:D5",
    "majorDimension": "ROWS",
    "values": [
    ["Item", "Cost", "Stocked", "Ship Date"],
    ["Wheel", "$20.50", "4", "3/1/2016"],   #new row
    ["Door", "$15", "2", "3/15/2016"],
    ["Engine", "$100", "1", "30/20/2016"],
    ["Totals", "=SUM(B2:B4)", "=SUM(C2:C4)", "=MAX(D2:D4)"]
    ],
} 

 which gives PUT https://sheets.googleapis.com/v4/spreadsheets/\
 spreadsheets/d/spreadsheetId/values/\
 sheet1!A1:D5?\valueInputOption=USER_ENTERED
        ^
 SyntaxError: invalid syntax

 This is copied directly from the API documentation.  Help! What is wrong?  
 Thanks.

1 个答案:

答案 0 :(得分:0)

writing guide告诉您使用此功能:

https://sheets.googleapis.com/v4/spreadsheets/spreadsheetId/values/Sheet1!A1:D5?valueInputOption=USER_ENTERED

另一方面,你正在使用这个:

https://sheets.googleapis.com/v4/spreadsheets/spreadsheets/d/\
    spreadsheetId/values/sheet1!A1:D5?valueInputOption=USER_ENTERED

网址看起来并不相同。您的网址中包含不需要的'\'字符。