【发布时间】:2016-06-12 09:23:32
【问题描述】:
我正在尝试在我的 Python 3.4 应用程序中实现“服务器到服务器”OAuth 身份验证,以便与 Google 云存储一起使用。所以,一般来说它在这个页面上描述Using OAuth 2.0 for Server to Server Applications
但是在我运行脚本时出现错误:
回溯(最近一次通话最后一次):
文件“my_script.py”,第 4 行,在 从 oauth2client.service_account 导入 ServiceAccountCredentials
文件 "/usr/local/lib/python3.4/dist-packages/oauth2client/service_account.py", 第 31 行,在 从 oauth2client.client 导入 SERVICE_ACCOUNTImportError:无法导入名称“SERVICE_ACCOUNT”
所以,这是我的代码:
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
from httplib2 import Http
scopes = ['https://www.googleapis.com/auth/cloud-platform.read-only']
credentials = ServiceAccountCredentials.from_json_keyfile_name('./keyfile.json', scopes)
http_auth = credentials.authorize(Http())
service = build('storage', 'v1', http=http_auth)
如果你能这么好心地帮助我,那就太好了!这是我第一个使用 Python 语言编写的脚本,而且我是 Python 和 Linux 世界的新手,所以我可能会错过一些非常明显的东西。
如果重要的话,我的操作系统是 Ubuntu 12.04。
谢谢!
【问题讨论】:
-
你需要显示其余的错误信息
-
@barny,哦,对不起,我的错。我已经更新了问题中的错误文本,这就是我在运行脚本时得到的全部内容
-
@barny,是的,我试图在那里找到类似的东西,但没有找到任何对我有帮助的东西。但也许你是对的,我应该在那里问
标签: python oauth google-api ubuntu-12.04 google-api-python-client