importTerror:无法导入名称SignedJwtAssertionCredentials

2024-05-23 19:09:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图通过Python客户端访问google应用程序,使用此代码获得授权(私有信息显然已被编辑):

import gflags
import httplib2

from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import SignedJwtAssertionCredentials
from oauth2client.tools import run

f = open('privatekey.p12', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
    service_account_name='name@developer.gserviceaccount.com',
    private_key=key,
    scope = 'https://www.googleapis.com/auth/calendar')
http = httplib2.Http()
http = credentials.authorize(http)
service = build(serviceName='calendar', version='v3', http=http)

但我收到这个错误:

ImportError: cannot import name SignedJwtAssertionCredentials

我已经安装了Google v3 API-Python客户端以及OAuth2;虽然我没有太多使用这些模块,但我似乎没有遇到任何其他问题。有人知道怎么回事吗?


Tags: keynamefromimportbuildcomhttp客户端
3条回答

我今天遇到这个问题,必须从oauth2client版本2.0回滚到版本1.5.2,其中:

pip install oauth2client==1.5.2

好像你还没有安装pyopenssl。通过easy_install pyopenssl安装。

Libraries oauth2client.client
if HAS_OPENSSL:
  # PyOpenSSL is not a prerequisite for oauth2client, so if it is missing then
  # don't create the SignedJwtAssertionCredentials or the verify_id_token()
  # method.

  class SignedJwtAssertionCredentials(AssertionCredentials):
....

最近更新了source repository以使用新代码:

from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

...

相关问题 更多 >