Python-Gmail API-“资源”的实例没有“用户”成员

问题描述 投票:4回答:1

[编辑]我现在已经在Linux发行版上尝试了Python快速入门指南,它可以按预期工作,这使我相信这是Windows唯一的问题。 [end_edit]

遵循以下Python快速入门指南:https://developers.google.com/gmail/api/quickstart/python

我遇到的问题是使用Python时,在]之后>

service = build('gmail','v1', http=creds.authorize(Http()))

下一行,这是:

results = service.users().labels().list(userID='me').execute()

我收到此错误:

Instance of 'Resource' has no 'users' member

现在我已经尝试了.NET快速入门指南,并且可以正常工作。由于某些原因,该API无法在python上运行。

我对google-api-python-client的pip安装说它是最新的。

我使用的是googleapiclient而不是apiclient,因为从我阅读的内容来看,apiclient仅出于遗留原因而存在,在此代码中使用它会导致错误“无法从apiclient导入构建”。

这里是我的pipfreeze

快速入门代码:

"""
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'])

[编辑]我现在已经在Linux发行版上尝试了Python快速入门指南,它可以按预期工作,这使我相信这是Windows唯一的问题。 [end_edit]按照Python快速入门...

python google-api google-oauth gmail-api google-api-python-client
1个回答
0
投票

应该是pylint问题。您可以通过在违规语句之后添加注释“#pylint:disable = maybe-no-member”来禁用特定行的pylint警告。

© www.soinside.com 2019 - 2024. All rights reserved.