GAE上不支持pycrypto随机?

时间:2014-09-12 07:36:33

标签: python google-app-engine pycrypto

我已经部署了一个使用pycrypto的App引擎应用程序。我在本地安装了pycrypto但是当我在App Engine上部署它时说:

TargetAppError: Traceback (most recent call last):
  File "/base/data/home/apps/s~shared-playground/55de226e3bc6746b0c2a029d52be624810ea0d14.376065013735366090/mimic/__mimic/target_env.py", line 968, in RunScript
    loader.load_module('__main__')
  File "/base/data/home/apps/s~shared-playground/55de226e3bc6746b0c2a029d52be624810ea0d14.376065013735366090/mimic/__mimic/target_env.py", line 316, in load_module
    return self.env.LoadModule(self, fullname)
  File "/base/data/home/apps/s~shared-playground/55de226e3bc6746b0c2a029d52be624810ea0d14.376065013735366090/mimic/__mimic/target_env.py", line 725, in LoadModule
    exec(code, module.__dict__)  # pylint: disable-msg=W0122
  File "helloworld.py", line 2, in <module>
    from pycrypto import Random
ImportError: No module named pycrypto

我有以下app.yaml:

application: my-app-id
version: 1
runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /.*
  script: helloworld.app

libraries:
- name: webapp2
  version: "2.5.2"
- name: pycrypto
  version: "2.6"

我的代码如下:

import webapp2
from Crypto.Cipher import AES
from Crypto import Random

from google.appengine.api import users

class MainPage(webapp2.RequestHandler):
    def get(self):
        user = users.get_current_user()

        if user:
            self.response.headers['Content-Type'] = 'text/plain'
            iv = Random.new().read(AES.block_size)
            key = b'Sixteen byte key'
            cipher = AES.new(key, AES.MODE_CFB, iv)
            msg = iv + cipher.encrypt(b'Attack at dawn')
            self.response.out.write('Hello, '+ msg + ': ' + user.nickname())


        else:
            self.redirect(users.create_login_url(self.request.uri))

app = webapp2.WSGIApplication([
    ('/', MainPage)
], debug=True)

错误的原因似乎相当简单。没有名为pycrypto的模块。但是,以下thread表明存在。那么这个错误的原因是什么?请告知谢谢。

1 个答案:

答案 0 :(得分:0)

App Engine在其沙箱中提供第三方库。找到下面的链接[1],了解App Engine支持的第三方库。您也可以尝试将版本更改为“最新”而不是2.6 在app.yaml

[1] https://cloud.google.com/appengine/docs/python/tools/libraries27