在heroku上部署flask应用,显示Internal Server Error怎么办?


$ heroku logs
2015-09-23T05:23:01.374916+00:00 app[web.1]: 2015-09-23 05:23:01 [9] [ERROR] Error handling request
2015-09-23T05:23:01.374920+00:00 app[web.1]: Traceback (most recent call last):
2015-09-23T05:23:01.374922+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 131, in handle_request
2015-09-23T05:23:01.374925+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
2015-09-23T05:23:01.374923+00:00 app[web.1]: respiter = self.wsgi(environ, resp.start_response)
2015-09-23T05:23:01.374927+00:00 app[web.1]: return self.wsgi_app(environ, start_response)
2015-09-23T05:23:01.374928+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
2015-09-23T05:23:01.374929+00:00 app[web.1]: response = self.make_response(self.handle_exception(e))
2015-09-23T05:23:01.374930+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
2015-09-23T05:23:01.374931+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2015-09-23T05:23:01.374933+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
2015-09-23T05:23:01.374934+00:00 app[web.1]: response = self.full_dispatch_request()
2015-09-23T05:23:01.374935+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
2015-09-23T05:23:01.374939+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2015-09-23T05:23:01.374936+00:00 app[web.1]: rv = self.handle_user_exception(e)
2015-09-23T05:23:01.374938+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
2015-09-23T05:23:01.374940+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
2015-09-23T05:23:01.374941+00:00 app[web.1]: rv = self.dispatch_request()
2015-09-23T05:23:01.374942+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
2015-09-23T05:23:01.374943+00:00 app web.1]: return self.view_functions[rule.endpoint
2015-09-23T05:23:01.374945+00:00 app[web.1]: File "/app/app/main/views.py", line 54, in index
2015-09-23T05:23:01.374946+00:00 app[web.1]: error_out=False)
2015-09-23T05:23:01.374947+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 405, in paginate
2015-09-23T05:23:01.374948+00:00 app[web.1]: items = self.limit(per_page).offset((page - 1) * per_page).all()
2015-09-23T05:23:01.374951+00:00 app[web.1]: return list(self)
2015-09-23T05:23:01.374950+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2323, in all
2015-09-23T05:23:01.374952+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2441, in __iter__
2015-09-23T05:23:01.374954+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2456, in _execute_and_instances
2015-09-23T05:23:01.374956+00:00 app[web.1]: result = conn.execute(querycontext.statement, self._params)
2015-09-23T05:23:01.374957+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 841, in execute
2015-09-23T05:23:01.374953+00:00 app[web.1]: return self._execute_and_instances(context)
2015-09-23T05:23:01.374965+00:00 app[web.1]: context)
2015-09-23T05:23:01.374962+00:00 app[web.1]: compiled_sql, distilled_params
2015-09-23T05:23:01.374961+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 938, in _execute_clauseelement
2015-09-23T05:23:01.374964+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1070, in _execute_context
2015-09-23T05:23:01.374966+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1271, in _handle_dbapi_exception
2015-09-23T05:23:01.374958+00:00 app[web.1]: return meth(self, multiparams, params)
2015-09-23T05:23:01.374970+00:00 app[web.1]: reraise(type(exception), exception, tb=exc_tb)
2015-09-23T05:23:01.374959+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 322, in _execute_on_connection
2015-09-23T05:23:01.374971+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1063, in _execute_context
2015-09-23T05:23:01.374960+00:00 app[web.1]: return connection._execute_clauseelement(self, multiparams, params)
2015-09-23T05:23:01.374972+00:00 app[web.1]: context)
2015-09-23T05:23:01.374978+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 442, in do_execute
2015-09-23T05:23:01.374967+00:00 app[web.1]: exc_info
2015-09-23T05:23:01.374968+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
2015-09-23T05:23:01.374980+00:00 app[web.1]: cursor.execute(statement, parameters)
2015-09-23T05:23:01.374982+00:00 app[web.1]: OperationalError: (OperationalError) no such table: posts u'SELECT posts.id AS posts_id, posts.body AS posts_body, posts.body_html AS posts_body_html, posts.timestamp AS posts_timestamp, posts.author_id AS posts_author_id \nFROM posts ORDER BY posts.timestamp DESC\n LIMIT ? OFFSET ?' (20, 0)
2015-09-23T05:24:50.869799+00:00 heroku[api]: Starting process with command bash by [email protected]
2015-09-23T05:24:55.344477+00:00 heroku[run.4472]: Awaiting client
2015-09-23T05:24:55.368866+00:00 heroku[run.4472]: Starting process with command bash
2015-09-23T05:24:55.736953+00:00 heroku[run.4472]: State changed from starting to up
2015-09-23T05:28:49.382001+00:00 heroku[run.4472]: State changed from up to complete
2015-09-23T05:28:49.370292+00:00 heroku[run.4472]: Process exited with status 130
2015-09-23T05:36:42.745968+00:00 heroku[router]: at=info method=GET path="/" host=young-sands-2229.herokuapp.com request_id=af9b3227-47ef-4bf5-aae9-d8b9332a949a fwd="182.204.118.65" dyno=web.1 connect=1ms service=34ms status=500 bytes=238
2015-09-23T05:36:42.729259+00:00 app[web.1]: 2015-09-23 05:36:42 [9] [ERROR] Error handling request
2015-09-23T05:36:42.729264+00:00 app[web.1]: Traceback (most recent call last):
2015-09-23T05:36:42.729271+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
2015-09-23T05:36:42.729267+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 131, in handle_request
2015-09-23T05:36:42.729268+00:00 app[web.1]: respiter = self.wsgi(environ, resp.start_response)
2015-09-23T05:36:42.729272+00:00 app[web.1]: return self.wsgi_app(environ, start_response)
2015-09-23T05:36:42.729274+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
2015-09-23T05:36:42.729275+00:00 app[web.1]: response = self.make_response(self.handle_exception(e))
2015-09-23T05:36:42.729276+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
2015-09-23T05:36:42.729278+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2015-09-23T05:36:42.729279+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
2015-09-23T05:36:42.729281+00:00 app[web.1]: response = self.full_dispatch_request()
2015-09-23T05:36:42.729282+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
2015-09-23T05:36:42.729284+00:00 app[web.1]: rv = self.handle_user_exception(e)
2015-09-23T05:36:42.729285+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
2015-09-23T05:36:42.729287+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2015-09-23T05:36:42.729288+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
2015-09-23T05:36:42.729289+00:00 app[web.1]: rv = self.dispatch_request()
2015-09-23T05:36:42.729304+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
2015-09-23T05:36:42.729306+00:00 app web.1]: return self.view_functions[rule.endpoint
2015-09-23T05:36:42.729317+00:00 app[web.1]: File "/app/app/main/views.py", line 54, in index
2015-09-23T05:36:42.729322+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 405, in paginate
2015-09-23T05:36:42.729321+00:00 app[web.1]: error_out=False)
2015-09-23T05:36:42.729324+00:00 app[web.1]: items = self.limit(per_page).offset((page - 1) * per_page).all()
2015-09-23T05:36:42.729325+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2323, in all
2015-09-23T05:36:42.729327+00:00 app[web.1]: return list(self)
2015-09-23T05:36:42.729331+00:00 app[web.1]: return self._execute_and_instances(context)
2015-09-23T05:36:42.729333+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2456, in _execute_and_instances
2015-09-23T05:36:42.729329+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2441, in __iter__
2015-09-23T05:36:42.729334+00:00 app[web.1]: result = conn.execute(querycontext.statement, self._params)
2015-09-23T05:36:42.729336+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 841, in execute
2015-09-23T05:36:42.729337+00:00 app[web.1]: return meth(self, multiparams, params)
2015-09-23T05:36:42.729340+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 322, in _execute_on_connection
2015-09-23T05:36:42.729341+00:00 app[web.1]: return connection._execute_clauseelement(self, multiparams, params)
2015-09-23T05:36:42.729343+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 938, in _execute_clauseelement
2015-09-23T05:36:42.729344+00:00 app[web.1]: compiled_sql, distilled_params
2015-09-23T05:36:42.729346+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1070, in _execute_context
2015-09-23T05:36:42.729347+00:00 app[web.1]: context)
2015-09-23T05:36:42.729349+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1271, in _handle_dbapi_exception
2015-09-23T05:36:42.729350+00:00 app[web.1]: exc_info
2015-09-23T05:36:42.729351+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
2015-09-23T05:36:42.729353+00:00 app[web.1]: reraise(type(exception), exception, tb=exc_tb)
2015-09-23T05:36:42.729355+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1063, in _execute_context
2015-09-23T05:36:42.729357+00:00 app[web.1]: context)
2015-09-23T05:36:42.729358+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 442, in do_execute
2015-09-23T05:36:42.729361+00:00 app[web.1]: cursor.execute(statement, parameters)
2015-09-23T05:36:42.729364+00:00 app[web.1]: OperationalError: (OperationalError) no such table: posts u'SELECT posts.id AS posts_id, posts.body AS posts_body, posts.body_html AS posts_body_html, posts.timestamp AS posts_timestamp, posts.author_id AS posts_author_id \nFROM posts ORDER BY posts.timestamp DESC\n LIMIT ? OFFSET ?' (20, 0)

flask gunicorn PostgreSQL python-flask heroku

功夫之王常威 9 years, 1 month ago

 OperationalError: (OperationalError) no such table: posts

没有初始化数据库吧

可以通过 heroku run xxx 执行命令来初始化数据库
https://devcenter.heroku.com/articles/getting-started-with-python#start-a-console

木瓜多瑙河 answered 9 years, 1 month ago

Your Answer