我在使用AWS RDS的ec2服务器上运行了一个巨大的工作烧瓶应用程序。我正在使用Apache与mod-wsgi。突然,所有提出查询的URI都会返回错误。
我无法发现为什么我开始得到"操作错误:没有这样的表:用户u' SELECT用户....'
该表显示在MySQL show tables中。此外,如果我登录到服务器,acvitavate virtualenv,并从python控制台运行:
from flask.ext.script import Manager
from myapp import create_app
from myapp.extensions import db
app=create_app()
manager=Manager(app)
ctx = app.app_context()
ctx.push()
我可以访问用户表和其他人。那么这里发生了什么?
我使用两种不同的配置(开发/生产)。这是通过使用环境变量完成的。如果我在生产服务器上运行上面的代码,那么我将获得生产配置。如何开始调试有问题的连接?
app.wsgi文件读起来像这样
import sys
sys.path.insert(0,"/var/www/myapp")
from myapp import create_app
application = create_app()
然后调用create_app,显然它会读取正确的配置。特别是,它将导入并运行
from flask.ext.sqlalchemy import SQLAlchemy
db = SQLAlchemy()
然后配置它
db.init_app(app)
apache2错误日志如下所示:
mod_authz_core.c(802): [client XXX.XX.XX.XX:29629] AH01626: authorization result of Require all granted: granted
mod_authz_core.c(802): [client XXX.XX.XX.XX:29629] AH01626: authorization result of <RequireAny>: granted
mod_authz_core.c(802): [client XXX.XX.XX.XX:29629] AH01626: authorization result of Require all granted: granted
mod_authz_core.c(802): [client XXX.XX.XX.XX:29629] AH01626: authorization result of <RequireAny>: granted
mod_wsgi (pid=6780, process='', application='ec2-XXX.XX.XX.XX.compute-1.amazonaws.com|'): Reloading WSGI script '/var/www/wsgi-scripts/app.wsgi'.
mod_wsgi (pid=6780): Exception occurred processing WSGI script '/var/www/wsgi-scripts/app.wsgi'.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1-py2.7.egg/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/Flask-0.10.1- py2.7.egg/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/var/www/myapp/myapp/frontend/views.py", line 71, in index
#current_app.logger.debug('debug')
File "/usr/local/lib/python2.7/dist-packages/Flask_SQLAlchemy-2.0- py2.7.egg/flask_sqlalchemy/__init__.py", line 431, in paginate
items = self.limit(per_page).offset((page - 1) * per_page).all()
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.8-py2.7- linux-x86_64.egg/sqlalchemy/orm/query.py", line 2320, in all
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.8-py2.7- linux-x86_64.egg/sqlalchemy/orm/query.py", line 2438, in __iter__
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.8-py2.7-linux-x86_64.egg/sqlalchemy/orm/query.py", line 2453, in _execute_and_instances
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.8-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py", line 729, in execute
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.8-py2.7-linux-x86_64.egg/sqlalchemy/sql/elements.py", line 322, in _execute_on_connection
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.8-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py", line 826, in _execute_clauseelement
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.8-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py", line 958, in _execute_context
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.8-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1159, in _handle_dbapi_exception
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.8-py2.7-linux-x86_64.egg/sqlalchemy/util/compat.py", line 199, in raise_from_cause
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.8-py2.7-linux-x86_64.egg/sqlalchemy/engine/base.py", line 951, in _execute_context
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.8-py2.7-linux-x86_64.egg/sqlalchemy/engine/default.py", line 436, in do_execute
OperationalError: (OperationalError) no such table: users u'SELECT users.password AS users_password, users.id AS users_id, users.name AS users_name, users.email AS users_email, users.openid AS users_openid, users.activation_key AS users_activation_key, users.created_time AS users_created_time, users.avatar AS users_avatar, users.role_code AS users_role_code, users.status_code AS users_status_code, users.user_detail_id AS users_user_detail_id, users.followers AS users_followers, users.following AS users_following \\nFROM users\\n LIMIT ? OFFSET ?' (10, 0)
答案 0 :(得分:0)
有一系列细节导致了这个问题。按照设计,首先加载默认配置,然后用行
覆盖它app.config.from_envvar("PRODUCTION_CFG",silent=True)
问题是环境变量是在我使用bash的会话中设置的,但是在服务器运行的会话中没有。我使用app.config.from_pyfile修改了它。