0

Using python 3.6, requests==2.22.0

Trying to create an event: documentation link

url = 'https://www.googleapis.com/calendar/v3/calendars/{}/events'.format(calendar_id)
data = {
      "summary": "CALENDAR TESTING",
      "location": "Some fake location",
      "description": "This is a test",
      "start": {
        "dateTime": "2019-10-09T09:00:00-07:00",
        "timeZone": "America/Los_Angeles",
      },
      "end": {
        "dateTime": "2019-10-09T10:00:00-07:00",
        "timeZone": "America/Los_Angeles",
      },
}
headers = {
        'Authorization': 'Bearer {}'.format(self.access_token.get('token')),
        'Accept': 'application/json',
        'Content-Type': 'application/json',
    }
response = requests.post(url, data=data, headers=headers)

print("Response: ", response)
j = response.json()
print("json: ", j)

Output:

Response:  <Response [400]>
Raw Response:  {'error': {'errors': [{'domain': 'global', 'reason': 'parseError', 'message': 'Parse Error'}], 'code': 400, 'message': 'Parse Error'}}

request body:

    summary=CALENDAR+TESTING&location=Some+fake+location&description=This+is+a+test&start=dateTime&start=timeZone&end=dateTime&end=timeZone

request headers:

    {'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json', 'Connection': 'keep-alive', 'Authorization': 'Bearer ******', 'Content-Type': 'application/json', 'Content-Length': '135'}

Stack posts that did not fix the issue:
stack post - re not setting content type, which I am
stack post - re apostrophes vs double quotes, I switched to double quotes still error

I did notice that the timezone information is missing from the request body, but I am not sure why, and if that is the issue.

I am looking into this post right now

camelBack
  • 748
  • 2
  • 11
  • 30

1 Answers1

0

A simple solution to fix the problem:

import json
response = requests.post(url, data=json.dumps(data), headers=headers)
camelBack
  • 748
  • 2
  • 11
  • 30