【发布时间】:2014-03-14 15:31:50
【问题描述】:
我正在尝试使用本地 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']
无论如何,在 sys.path 中添加 "/usr/local/lib/python2.7/site-packages/OpenSSL" 或在 /Users/mattes/Developer/gae-projects/project123 下符号链接 /usr/local/lib/python2.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
有人可以帮忙吗?
【问题讨论】:
-
oauth2client模块在哪里?它在您的 apppengine 项目文件夹中吗? -
"解释器不能用 C 代码加载 Python 模块;它是一个“纯” Python 环境。" (developers.google.com/appengine/docs/python/…) 那么可能是 crypto.so 文件的问题?
-
"Python 运行环境的所有代码都必须是纯 Python,并且不包含任何 C 扩展或其他必须编译的代码。" developers.google.com/appengine/docs/python/#Python_Pure_Python
标签: python google-app-engine google-oauth google-bigquery