Rohit Awasthi
Rohit Awasthi

Reputation: 686

gmail python client api import message shows Syntax error

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

Upvotes: 0

Views: 416

Answers (2)

Rohit Awasthi
Rohit Awasthi

Reputation: 686

I found a comment by user cdleary that helped. Work-around is I appended _ to import. service.users().messages().import_() is working. Though still I have issue open in Google issue tracker.

Upvotes: 2

payne
payne

Reputation: 14177

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

Upvotes: 1

Related Questions