首页 > 解决方案 > Invalid JSON payload received. Unknown name at 'requests[1].paste_data.data': Cannot find field

问题描述

UPDATE: I used the api explorer on the google bactch update page and was able to successfully update the spreadsheet but when I replicate this in my code I am still getting an error. The API explorer did work with the json format.

<HttpError 400 when requesting
Invalid JSON payload received. Unknown name "value_input_option" at 'requests[0]': Cannot find field.
Invalid JSON payload received. Unknown name "data" at 'requests[0]': Cannot find field.">



scope = ['https://spreadsheets.google.com/feeds',
     'https://www.googleapis.com/auth/drive']
creds = 
ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
service = discovery.build('sheets', 'v4', credentials=creds)
client = gspread.authorize(creds)

# find workbook by name and open the first sheet
# make sure you use the right name here
sheet = client.open("forklift").sheet1

# extract and print all of the values
# list_of_hashes = sheet.get_all_records()

spreadsheet_id = '112345'


batch_update_spreadsheet_request_body =  {
     "requests": [

{
    "valueInputOption": "RAW",
    "data": [
        {
            "majorDimension": "ROWS",
            "range": "43:48",
            "values": [
                ["www.colossalpoint.com","colossal point llc"]
            ]
        }
    ]
}
  ],
  "includeSpreadsheetInResponse": True,
  "responseIncludeGridData": True
}


request = service.spreadsheets().batchUpdate(spreadsheetId=spreadsheet_id,
                                         body=batch_update_spreadsheet_request_body)
response = request.execute()

标签: pythongoogle-apigoogle-api-python-clientpygsheets

解决方案


推荐阅读