我遇到了试图在EB上运行我的python web应用程序的问题。它在本地运行良好,但是当我在EB上运行时,我得到以下异常。问题似乎是它遇到异常,但堆栈跟踪是在原始异常之后发生的错误,所以我无法确定根本原因是什么:
Exception on /admin GET
Traceback (most recent call last):
File "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functionshttp://rule.endpoint(**req.view_args)
File "/opt/python/run/venv/lib/python2.7/site-packages/sandman/sandman.py", line 459, in get_collection
cls = endpoint_class(collection)
File "/opt/python/run/venv/lib/python2.7/site-packages/sandman/sandman.py", line 185, in endpoint_class
cls = current_app.class_referencescollection
File "/opt/python/run/venv/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'Flask' object has no attribute 'class_references'
当我在SSH连接到我的实例后手动启动端口5000上的应用程序,并尝试从控制台加载同一页面时,我没有收到任何错误(并且保存的文件包含正确的HTML):
wget http://127.0.0.1:5000/admin
--2014-03-23 17:01:13-- http://127.0.0.1:5000/admin
Connecting to 127.0.0.1:5000... connected.
HTTP request sent, awaiting response... 127.0.0.1 - - 23/Mar/2014 17:01:13 "GET /admin HTTP/1.1" 301 -
301 MOVED PERMANENTLY
Location: http://127.0.0.1:5000/admin/ following
--2014-03-23 17:01:13-- http://127.0.0.1:5000/admin/
Connecting to 127.0.0.1:5000... connected.
HTTP request sent, awaiting response... 127.0.0.1 - - 23/Mar/2014 17:01:13 "GET /admin/ HTTP/1.1" 200 -
200 OK
Length: 1519 (1.5K) text/html
Saving to: ‘admin’
这是我正在运行的python应用代码:http://pastebin.com/qgnWz6aK
答案 0 :(得分:1)
我设法通过使用Tornado来解决这个问题(尽管我仍然不确定底层问题是什么):
from sandman import app
from sandman.model import activate
import logging
import os, sys
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DB']
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
activate(browser=False)
app.debug = True
http_server = HTTPServer(WSGIContainer(app))
http_server.listen(os.environ['PORT'])
IOLoop.instance().start()