python - Python - Gmail API - “资源”实例没有“用户”成员
问题描述
[编辑] 我现在已经在我的 linux 发行版上尝试了 Python 快速入门指南,它按预期工作,这让我相信这是一个仅限 Windows 的问题。[结束编辑]
遵循此处的 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'])
解决方案
应该是pylint问题。您可以通过在违规语句后添加注释“# pylint: disable=maybe-no-member”来禁用特定行的 pylint 警告。
http://pylint.pycqa.org/en/latest/#is-it-possible-to-locally-disable-a-particular-message
推荐阅读
- php - 当我尝试更新表中的信息时是否出现错误?
- python - 已解决:如果找不到数据,sqlalchemy session.query...first() 会崩溃
- git - 错误:无法锁定配置文件 .git/config:没有这样的文件或目录
- c# - 如何在 DocuSign 中预填充带有验证的字段?
- java - 如何在 Clojure 中使用 java.util.stream.Stream?
- ruby-on-rails - 如何在 API 模式下在 Rails 应用程序中实现 JWT 身份验证
- c - 检查字符串是否为空,然后继续
- hyperlink - Maximo启动中心中的超链接?
- javascript - 为 SASS(编译、Prod 中的缩小)、JS(Concat + 缩小)和多个 Vue 单页应用程序构建 Webpack 4 配置
- python - Python - 多处理过程模块 - 未定义函数变量?