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

时间:2022-06-15 14:06:58

I am trying to connect to the BigQuery API locally with my local dev_appserver, following this tutorial: https://developers.google.com/bigquery/authorization?hl=de#service-accounts Running the code mentioned on this site, returns an ImportError:

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

ImportError: cannot import name SignedJwtAssertionCredentials

So I followed the error and spotted (in oauth2client/client.py):

所以我跟着错误发现了(在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):

But I need "SignedJwtAssertionCredentials"! So I isolated the error further and found (in oauth2client/crypt.py) that this line is actually causing this issue:

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

from OpenSSL import crypto

I tried:

我试过了:

$ 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'

which looks promising and also checked the sys.path of my code:

看起来很有前途,还检查了我的代码的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']

Anyway, neither adding "/usr/local/lib/python2.7/site-packages/OpenSSL" to the sys.path nor symlinking /usr/local/lib/python2.7/site-packages/OpenSSL under /Users/mattes/Developer/gae-projects/project123 fixes this issue.

无论如何,既没有将“/usr/local/lib/python2.7/site-packages/OpenSSL”添加到sys.path中,也没有在/ Users / mattes下添加/mlr /local/lib/python2.7/site-packages/OpenSSL / Developer / gae-projects / project123解决了这个问题。

/usr/local/lib/python2.7/site-packages/OpenSSL looks like:

/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

using Mac 10.9 Mavericks, Python 2.7.5

使用Mac 10.9 Mavericks,Python 2.7.5

Can somebody help?

有人可以帮忙吗?

2 个解决方案

#1


5  

To get this running on the GAE servers I found that three steps were necessary:

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

  1. Install the up-to-date version of the Google API Client (or at least the oauth2client module). Note that they provide a GAE targetted download.

    安装最新版本的Google API客户端(或至少安装oauth2client模块)。请注意,它们提供了GAE目标下载。

  2. Convert my .p12 key file to a .pem format (using the openssl command line tools)

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

    openssl pkcs12  -nocerts -in cert.p12 -out cert.pem
    
  3. Add the PyCrypto library to the app.yaml.

    将PyCrypto库添加到app.yaml。

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

For dev_appserver it was also necessary to install the PyCrypto library locally, as it is not contained in the SDK. (OpenSSL is also supported by the API Client library, but I assume that using PyCrypto stays closer to the runtime environment.)

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

#2


3  

Fixed the issue by adding pycrypto to libraries section in my app.yaml:

修复了我的app.yaml中将pycrypto添加到库部分的问题:

libraries:

- name: pycrypto
  version: "latest"

#1


5  

To get this running on the GAE servers I found that three steps were necessary:

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

  1. Install the up-to-date version of the Google API Client (or at least the oauth2client module). Note that they provide a GAE targetted download.

    安装最新版本的Google API客户端(或至少安装oauth2client模块)。请注意,它们提供了GAE目标下载。

  2. Convert my .p12 key file to a .pem format (using the openssl command line tools)

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

    openssl pkcs12  -nocerts -in cert.p12 -out cert.pem
    
  3. Add the PyCrypto library to the app.yaml.

    将PyCrypto库添加到app.yaml。

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

For dev_appserver it was also necessary to install the PyCrypto library locally, as it is not contained in the SDK. (OpenSSL is also supported by the API Client library, but I assume that using PyCrypto stays closer to the runtime environment.)

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

#2


3  

Fixed the issue by adding pycrypto to libraries section in my app.yaml:

修复了我的app.yaml中将pycrypto添加到库部分的问题:

libraries:

- name: pycrypto
  version: "latest"