0

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

Rohit Awasthi
  • 686
  • 3
  • 12
  • 1
    Some of the time, on a syntax error, the problem comes in the lines _before_ where the error message says it is. Show us a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – DavidG Dec 22 '17 at 09:41
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example. – Linda Lawton - DaImTo Dec 22 '17 at 09:42
  • @DavidG DalmTo. okay – Rohit Awasthi Dec 22 '17 at 09:49

2 Answers2

2

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.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Rohit Awasthi
  • 686
  • 3
  • 12
1

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

payne
  • 13,833
  • 5
  • 42
  • 49