python - 加密不可用错误: No crypto library available (using oauth2client in google app engine)

标签 python google-app-engine pyopenssl oauth2client gspread

我正在使用 gspread 将我的应用程序连接到电子表格,为此我使用以下代码

import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials

json_key = json.load(open('service_account.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
gc = gspread.authorize(credentials)
sheet = gc.open('Order Database').sheet1

当我在空闲状态下使用它来访问电子表格时,同样的代码工作得很好。但是当我在我的应用程序的代码中使用它时(我正在使用 Google App Engine),当我运行应用程序并尝试访问页面时出现此错误

ERROR    2015-09-14 08:49:44,263 wsgi.py:263] 
Traceback (most recent call last):
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/Users/mbp13inch/Documents/Workspace/ehscanteen/main.py", line 15, in <module>
    db = Database()
  File "/Users/mbp13inch/Documents/Workspace/ehscanteen/server.py", line 10, in __init__
    credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
  File "/Users/mbp13inch/Documents/Workspace/ehscanteen/lib/oauth2client/util.py", line 142, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Users/mbp13inch/Documents/Workspace/ehscanteen/lib/oauth2client/client.py", line 1622, in __init__
    _RequireCryptoOrDie()
  File "/Users/mbp13inch/Documents/Workspace/ehscanteen/lib/oauth2client/client.py", line 1573, in _RequireCryptoOrDie
    raise CryptoUnavailableError('No crypto library available')
CryptoUnavailableError: No crypto library available

我什至成功地将库安装在项目目录中:

pip install -t lib PyOpenSSL
pip install -t lib gspread
pip install -t lib oauth2client
pip install -t lib cryptography 

我什至尝试将 --upgrade 添加到每个文件中,并且所有文件都安装成功,但遇到了相同的错误

请告诉我我是否做错了什么以及如何解决这个问题?

提前致谢。

最佳答案

好吧,我终于解决了这个问题。我实际上所要做的就是将以下内容添加到 app.yaml :

libraries:
- name: pycrypto
  version: "latest"

关于python - 加密不可用错误: No crypto library available (using oauth2client in google app engine),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32560825/

相关文章:

python - Pandas:加速许多字符串搜索

Python Pip 安装失败 - 无法构建 Egg。由于 google cloud sql 也无法使用 1.2.5

google-app-engine - 如何在 App Engine 上禁用 PageSpeed 服务的 URL?

python-3.x - 有人可以解释一下 SSL 证书的回调函数吗?

python - 增加单个 socket.send() 调用中发送的数据量

python - 快速 MySQL 导入

java - 如何从当前项目引用另一个Java项目?

google-app-engine - 授予 Google Cloud Storage REST API 的目录级权限

x509certificate - PyOpenSSL读取证书/pkey文件

python - 毒性 0% 覆盖率