I am trying to write (append) string of python dict to Google Sheets
below is my code
SCOPES = 'https://www.googleapis.com/auth/spreadsheets.readonly'
SPREADSHEET_ID = 'XXX'
RANGE_NAME = 'Sheet1!A2:F2'
now = time.strftime('%d-%m-%Y %H:%M')
def main():
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('sheets', 'v4', http=creds.authorize(Http()))
request = service.spreadsheets().values().append(spreadsheetId= SPREADSHEET_ID,
range= RANGE_NAME,
valueInputOption='USER_ENTERED',
insertDataOption='INSERT_ROWS',
body= {now, data2['pagespeed_score'], data2['yslow_score'], Loadedtime, pagesize, data2['page_elements'],})
response = request.execute()
print(response)
if __name__ == '__main__':
main()
But I am getting an error:
"TypeError: {2.1982345581054688, '11-09-2018 13:08', 8.836, 109, 52, 55} is not JSON serializable"
What I think is the values should be in json format but my values are in python dictionary.
key=value
to make a dictionary. – floydya Sep 11 '18 at 7:23values#append
, thebody
parameter must be aValueRange
: developers.google.com/sheets/api/reference/rest/v4/… Review the API docs and possibly also the Python Client Library docs: developers.google.com/resources/api-libraries/documentation/… – tehhowch Sep 11 '18 at 18:32