gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:43:52 24 4
gpt4 key购买 nike

[编辑] 我现在已经在我的 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'])

最佳答案

应该是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

关于Python - Gmail API - 'Resource' 的实例没有 'users' 成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50948314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com