首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python - Gmail API - 'Resource‘的实例没有'users’成员

Python - Gmail API - 'Resource‘的实例没有'users’成员
EN

Stack Overflow用户
提问于 2018-06-20 20:29:35
回答 1查看 3.4K关注 0票数 6

编辑我现在已经在我的linux发行版上尝试了Python快速入门指南,它可以正常工作,这让我相信这只是一个windows问题。end_edit

遵循这里提供的Python快速入门指南:https://developers.google.com/gmail/api/quickstart/python

我遇到的问题是在使用Python时,在

代码语言:javascript
运行
复制
service = build('gmail','v1', http=creds.authorize(Http()))

下一行是:

代码语言:javascript
运行
复制
results = service.users().labels().list(userID='me').execute()

我得到了这个错误:

代码语言:javascript
运行
复制
Instance of 'Resource' has no 'users' member

现在,我已经尝试了.NET快速入门指南,它是有效的。由于某些原因,API不能在python上工作。

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

我使用googleapiclient而不是apiclient,因为据我所知,apiclient只是因为遗留的原因而存在,在这段代码中使用它会导致错误"cannot import build from apiclient“。

这是我的pipfreeze

快速入门代码:

代码语言:javascript
运行
复制
"""
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'])
EN

回答 1

Stack Overflow用户

发布于 2020-03-25 23:19:16

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

请参阅Hide some maybe-no-member Pylint errors

http://pylint.pycqa.org/en/latest/#is-it-possible-to-locally-disable-a-particular-message

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50948314

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档