Ali Nahid Ali Nahid - 1 year ago 191
Python Question

Python client library for Google Calendar API v3 insert event throwing "Missing end time" error

I have searched the web for the solution but it seemed I am the only one who couldn't solve this issue.

So this is what my python code looks like:

class ReminderDate(object):
def __init__(self, datetimestring, timezone="Australia/Sydney"):
self.dateTime = datetimestring
self.timeZone = timezone
class ReminderFormat(object):
def __init__(self, useDefault=False):
self.useDefault = useDefault
self.overrides = [{"method":"email", "minutes":15}]
class ReminderData(object):
def __init__(self, reminder, datefrom=None, dateto=None, datevalue=None):
self.summary = reminder
self.start = ReminderDate(datefrom)
self.end = ReminderDate(dateto)
self.reminders = ReminderFormat()

def save_event_to_google_calendar(self, reminder_data):
credentials = self.get_credentials()
service = build('calendar', 'v3', http=credentials.authorize(Http()))
event = json.dumps(reminder_data, default=lambda o: o.__dict__)
print (event)
created_event =, body=str(event), sendNotifications=True).execute()

And it produces hence the print(event) outputs a json like below:

{"start": {"timeZone": "Australia/Sydney",
"dateTime": "2015-04-26T18:45:00+10:00"},
"end": {"timeZone": "Australia/Sydney",
"dateTime": "2015-04-26T19:00:00.000+10:00"},
"reminders": {"overrides": [{"minutes": 15, "method": "email"}],
"useDefault": false},
"summary": "do grocery shopping"}

and I get the following error:

File "/usr/local/lib/python2.7/dist-packages/googleapiclient/", line 729, in execute
raise HttpError(resp, content, uri=self.uri)
<HttpError 400 when requesting
returned "Missing end time.">

I dont understand. I have the "end" time in the json. Then what am I missing here ?

I have tried posting the same json via the google developer console and it works.
BUT it fails from the python client library :( (described above)

[EDIT] Solution found

The issue was that I had converted Python Object to JSON "string" and that's what I was supplying as opposed to JSON "object" expected by the API.
So this is the right code:

json_event = json.loads(event)
created_event =, body=json_event, sendNotifications=True).execute()

Answer Source

Try adding:

httplib2.debuglevel = 4

just before the API call. This will allow you to see the exact body that the events.insert() request is sending. Compare that to the body produced by API explorer and you should have your answer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download