Python ImportError:无法导入名称SignedJwtAssertionCredentials

Python ImportError:无法导入名称SignedJwtAssertionCredentials,python,google-api,oauth-2.0,Python,Google Api,Oauth 2.0,我正试图通过Python客户端访问google应用程序,使用此代码获得授权(私人信息显然已编辑): 但我收到了这个错误: ImportError: cannot import name SignedJwtAssertionCredentials 我已经安装了Google v3 API Python客户端以及OAuth2;我似乎没有任何其他问题与这些模块,虽然我没有使用他们太多。有人知道发生了什么吗 您似乎还没有安装pyopenssl。通过easy\u安装pyopenssl安装 Librarie

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

但我收到了这个错误:

ImportError: cannot import name SignedJwtAssertionCredentials

我已经安装了Google v3 API Python客户端以及OAuth2;我似乎没有任何其他问题与这些模块,虽然我没有使用他们太多。有人知道发生了什么吗

您似乎还没有安装pyopenssl。通过
easy\u安装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):
....

正如alexander margraf所说,您需要PyOpenSSL来导入SignedJwtAssertionCredentials

简单:pip安装pyopenssl


请记住:如果您没有安装OpenSSL Win32 LIB(您需要完整的软件包,而不是light版本),它将在Windows上失败。还要记住,在安装pyopenssl之前,您需要将其添加到path var中。我试图构建一个本地开发环境,但这里的解决方案都不起作用。对我来说,拼图中的额外部分是:

$ pip install pycrypto
可能除了以下任何或全部内容之外:

$ pip install pyopenssl
$ pip install httplib2
$ pip install oauth2client
$ pip install ssl

(检查你的app.yaml中列出的库)这样一些需要它的东西可能会在他们的机器上工作,但不会在你的机器上工作-我想-对不起,我还不清楚是什么以及为什么他们使用这些库让生活如此痛苦。

我今天遇到了这个问题,不得不从oauth2client 2.0版回滚到1.5.2版,包括:

pip install oauth2client==1.5.2
最近更新了,以利用新代码:

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

...

首先检查您的
oauth2client
版本

如果此版本>=2.0,请使用
ServiceAccountCredentials
而不是
SignedJwtAssertionCredentials

请看三个参考:

  • 问题:
  • 升级到2.0
  • 文件

检查您的“oauth2client”模块版本,可能您使用的是高于1.5.2的版本。如果是这样,您可以通过降级版本并重新安装1.5.2或“oauth2client.client.AccessTokenCredentials”来解决此问题。文档链接

您可以在oauth2client版本>=2.0时尝试此功能

从oauth2client.service\u帐户导入ServiceAccountCredentials
ServiceAccountCredentials.from_p12_密钥文件(
服务\帐户\电子邮件地址:name@developer.gserviceaccount.com', 
filename=键路径,
范围https://www.googleapis.com/auth/calendar')

听起来像是谷歌第一次发现这个错误:是的,但他们的AppAssertion解决方案并不理想——我想知道StackOverflow是否有其他方法。如果没有OpenSSL,Win32安装pyopenssl会失败,并出现以下错误:“错误:只找到不正确的OpenSSL目录:…”我安装了pyopenssl(
sudo-pip-install-pyopenssl
)但我仍然收到了问题中的错误(在OSX 10.8.5上使用Python 2.7)。我的修复方法是运行
sudo-pip-install-pyopenssl-upgrade
。谢谢兄弟。经过漫长的旅程,你的答案终于有帮助了:-)如上所述,michael解释说,SignedJwtAssertionCredentials已被删除,其行为现在在auth2client.service_account.ServiceAccountCredentials中实现。此修复程序不再适用于google api客户端,因为它已更新为需要oauthclient 2.0+。如上所述,将SignedJwtAssertionCredentials更改为ServiceAccountCredentials是您想要做的。为什么此注释不是答案。我正在使用指挥棒,我面临着同样的问题,这是唯一一个对medid有效的答案。你阅读了已经发布的其他答案吗?请添加详细信息,解释为什么您的答案会添加现有答案中尚未包含的重要信息
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

...