Using the quickstart guide for the Gmail API with Python, I get an 400 error "Invalid to header" when trying to create a draft.
I have been using my little script for a few weeks and it worked perfectly fine to create invoice drafts in bulk, until one day it just stopped working even though I had not modified any code.
This is the error I get:
1 file(s) copied.
Traceback (most recent call last):
File "quickstart.py", line 223, in <module>
main()
File "quickstart.py", line 207, in main
create_draft(service, 'me', message_body)
File "quickstart.py", line 134, in create_draft
draft = service.users().drafts().create(userId=user_id, body=message).execute()
File "C:\Users\$User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\googleapiclient\_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\$User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\googleapiclient\http.py", line 842, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/gmail/v1/users/me/drafts?alt=json returned "Invalid to header">
When I got this error for the first time, I deleted the credentials file and downloaded a new one. But now this solution doesn't seem to work anymore.
Does the credentials.json file expire after some time?