2014-02-15 63 views
2

我想用我的地方dev_appserver本地连接的BigQuery API,下面这个教程:https://developers.google.com/bigquery/authorization?hl=de#service-accounts 运行此网站上提到的代码,返回一个ImportError:命名OpenSSL.crypto和导入错误无模块:SignedJwtAssertionCredentials

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我的代码。路径:

['/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也不符号链接/usr/local/lib/python2.7/site-packages/OpenSSL/Users/mattes/Developer/gae-projects/project123修复此问题。

/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小牛的Python 2.7.5

有人能帮忙吗?

+0

“oauth2client”模块位于何处?它在你的apppengine项目文件夹中吗? –

+1

是的。从https://code.google.com/p/google-api-python-client/downloads/detail?name=google-api-python-client-gae-1.2.zip&can=2&q= – mattes

+0

下载解释器无法加载具有C代码的Python模块;它是一个“纯粹的”Python环境。“ (https://developers.google。com/appengine/docs/python /#Python_Introduction)或许crypto.so文件是问题所在? – mattes

回答

3

在我app.yaml加入pycryptolibraries部分修正了问题:

libraries: 

- name: pycrypto 
    version: "latest" 
+0

将appcrypto添加到app.yaml中是做什么的?它是否强制更新Python OpenSSL包装? – Cyrille

5

要获得GAE服务器我发现三个步骤是必要的这一运行:

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

  2. 转换我的.p12密钥文件的.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中包含。 (OpenSSL也受API客户端库支持,但我认为使用PyCrypto可以更接近运行时环境。)

+0

对我来说,作为PyCrypto的依赖包含的'pycparser/__ init __。py'试图导入'subprocess.Popen',并且在App Engine python环境中失败。这导致'oauth2client/client.py'中的'HAS_CRYPTO'检查失败,因此'SignedJwtAssertionCredentials'没有被定义。 (我使用的是苹果机) –

+0

@EricWalker我在Mac上遇到同样的问题。你解决了吗? – poiuytrez

+0

@poiuytrez,自从我处理这个问题以来已经有一段时间了,但我记得终于可以开始工作了。我不记得我做了什么。 –

相关问题