我已经部署了一个使用pycrypto的应用程序引擎应用程序。我在本地安装了pycrypto,但当我在应用程序引擎上部署时,它说:
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
我有以下应用程序:
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的模块。然而,下面的线索表明确实存在。那么这个错误的原因是什么?请告知,谢谢。
App Engine在其沙箱中提供第三方库。查找下面的链接[1],了解App Engine支持的第三方库。您还可以尝试将版本更改为"最新",而不是2.6在app.yaml 中
[1]https://cloud.google.com/appengine/docs/python/tools/libraries27