问题
gmail python api service.users().messages().import
shows Syntax error here is line of code
mgg = services.users().messages().import(userId='me', raw=base64.urlsafe_b64encode(mime_msg.as_string()), labelIds=mime_msg.get('labelIds')).execute()
error is showing at bracket of import(
If I change import
to something such as importee
then it is showing this error
AttributeError: 'Resource' object has no attribute 'importee'
So looks like it is related to?
Python Reserved Keyword
I have also submitted bug in gmail api here is link to google issue tracker
回答1:
Searched on SSO and found a comment by SSO user cdleary
link to question is this : though its not exact same but comment on that question helped Link to that question is it.
So work-around is I prefixed "_" to "import" keyword so
service.users().messages().import_()
is working. Though still I have issue open in google issue tracker.
回答2:
Yes, since import is a reserved word in Python, the Google python library will append a "_" to the API method name. Use:
service.users().messages().import_(....)
The documentation is currently (as of late 2017) incorrect and there's an open issue to fix it. See: https://github.com/google/google-api-python-client/issues/408
来源:https://stackoverflow.com/questions/47939137/gmail-python-client-api-import-message-shows-syntax-error