gpt4 book ai didi

python - 没有名为 OpenSSL.crypto 和 ImportError : SignedJwtAssertionCredentials 的模块

转载 作者:行者123 更新时间:2023-11-28 20:22:59 25 4
gpt4 key购买 nike

我正在尝试使用我的本地 dev_appserver 在本地连接到 BigQuery API,遵循本教程:https://developers.google.com/bigquery/authorization?hl=de#service-accounts运行本网站上提到的代码,返回 ImportError:

ImportError: cannot import name SignedJwtAssertionCredentials

所以我跟踪错误并发现(在 oauth2client/client.py 中):

if HAS_CRYPTO:
# PyOpenSSL and PyCrypto are not prerequisites for oauth2client, so if it is
# missing then don't create the SignedJwtAssertionCredentials or the
# verify_id_token() method.

class SignedJwtAssertionCredentials(AssertionCredentials):

但我需要“SignedJwtAssertionCredentials”!所以我进一步隔离了错误并发现(在 oauth2client/crypt.py 中)这一行实际上导致了这个问题:

from OpenSSL import crypto

我试过:

$ python
>>> import OpenSSL
>>> OpenSSL.__file__
'/usr/local/lib/python2.7/site-packages/OpenSSL/__init__.pyc'
>>> from OpenSSL import crypto
>>> crypto.__file__
'/usr/local/lib/python2.7/site-packages/OpenSSL/crypto.so'

这看起来很有希望并且还检查了我代码的 sys.path:

['/Users/mattes/Developer/gae-projects/project123', 
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine',
'/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/protorpc-1.0',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob-1.1.1',
'/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/yaml-3.10']

无论如何,既不添加 "/usr/local/lib/python2.7/site-packages/OpenSSL" 到 sys.path 也不符号链接(symbolic link) /usr/local/lib/python2 /Users/mattes/Developer/gae-projects/project123 下的 .7/site-packages/OpenSSL 修复了这个问题。

/usr/local/lib/python2.7/site-packages/OpenSSL 看起来像:

├── SSL.so
├── __init__.py
├── __init__.pyc
├── crypto.so
├── rand.so
├── test
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── test_crypto.py
│   ├── test_crypto.pyc
│   ├── test_rand.py
│   ├── test_rand.pyc
│   ├── test_ssl.py
│   ├── test_ssl.pyc
│   ├── util.py
│   └── util.pyc
├── tsafe.py
├── tsafe.pyc
├── version.py
└── version.pyc

使用 Mac 10.9 Mavericks、Python 2.7.5

有人可以帮忙吗?

最佳答案

为了让它在 GAE 服务器上运行,我发现需要三个步骤:

  1. 安装最新版本的 Google API Client (或者至少是 oauth2client 模块)。请注意,它们提供了针对 GAE 的下载。

  2. 将我的 .p12 key 文件转换为 .pem 格式(使用 openssl 命令行工具)

    openssl pkcs12  -nocerts -in cert.p12 -out cert.pem
  3. 将 PyCrypto 库添加到 app.yaml。

    libraries:
    - name: pycrypto
    version: "2.6" # this could be "latest" if you are daring

对于 dev_appserver,还需要在本地安装 PyCrypto 库,因为它不包含在 SDK 中。 (API 客户端库也支持 OpenSSL,但我假设使用 PyCrypto 更接近运行时环境。)

关于python - 没有名为 OpenSSL.crypto 和 ImportError : SignedJwtAssertionCredentials 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21793471/

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