[edit] I have now tried the Python quickstart guide on my linux distro and it is working as intended, which makes me believe this is a windows only issue. [end_edit]
Following the Python Quickstart guide found here: https://developers.google.com/gmail/api/quickstart/python
The problem I am getting is when using Python, after the
service = build('gmail','v1', http=creds.authorize(Http()))
The next line, which is this:
results = service.users().labels().list(userID='me').execute()
I am getting this error:
Instance of 'Resource' has no 'users' member
Now I have tried the .NET quickstart guide and that works. For some reason the API isn't working on python.
My pip install of the google-api-python-client says it is up to date.
I am using googleapiclient instead of apiclient because from what I have read, apiclient was only there for legacy reasons and using it in this code would result in the error "cannot import build from apiclient".
Here is my pipfreeze
Quickstart code:
"""
Shows basic usage of the Gmail API.
Lists the user's Gmail labels.
"""
from __future__ import print_function
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
# Setup the Gmail API
SCOPES = 'https://www.googleapis.com/auth/gmail.readonly'
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('gmail', 'v1', http=creds.authorize(Http()))
# Call the Gmail API
results = service.users().labels().list(userId='me').execute()
labels = results.get('labels', [])
if not labels:
print('No labels found.')
else:
print('Labels:')
for label in labels:
print(label['name'])
It should be pylint issue. You can disable pylint warnings for a specific line by adding a comment "# pylint: disable=maybe-no-member" after the offending statement.
see Hide some maybe-no-member Pylint errors
http://pylint.pycqa.org/en/latest/#is-it-possible-to-locally-disable-a-particular-message
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With