flask经常报奇怪的错误


代码只有一行


 topic = Topic.query.filter_by(topic_domain=topic_domain).first()

刷新10次就可能有一次报下面的错误:

Traceback (most recent call last): File
"/var/www/topicdm/venv/lib/python2.7/site-packages/flask/app.py", line
1836, in call
return self.wsgi_app(environ, start_response) File "/var/www/topicdm/venv/lib/python2.7/site-packages/flask/app.py", line
1820, in wsgi_app
response = self.make_response(self.handle_exception(e)) File "/var/www/topicdm/venv/lib/python2.7/site-packages/flask/app.py", line
1403, in handle_exception
reraise(exc_type, exc_value, tb) File "/var/www/topicdm/venv/lib/python2.7/site-packages/flask/app.py", line
1817, in wsgi_app
response = self.full_dispatch_request() File "/var/www/topicdm/venv/lib/python2.7/site-packages/flask/app.py", line
1477, in full_dispatch_request
rv = self.handle_user_exception(e) File "/var/www/topicdm/venv/lib/python2.7/site-packages/flask/app.py", line
1381, in handle_user_exception
reraise(exc_type, exc_value, tb) File "/var/www/topicdm/venv/lib/python2.7/site-packages/flask/app.py", line
1475, in full_dispatch_request
rv = self.dispatch_request() File "/var/www/topicdm/venv/lib/python2.7/site-packages/flask/app.py", line
1461, in dispatch_request
return self.view_functions rule.endpoint File "./app/views.py", line 479, in traffic
topic = Topic.query.filter_by(topic_domain=g.host).first() File "/var/www/topicdm/venv/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
line 2367, in first
ret = list(self[0:1]) File "/var/www/topicdm/venv/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
line 2228, in getitem
return list(res) File "/var/www/topicdm/venv/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
line 2438, in iter
return self._execute_and_instances(context) File "/var/www/topicdm/venv/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
line 2453, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params) File "/var/www/topicdm/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 729, in execute
return meth(self, multiparams, params) File "/var/www/topicdm/venv/lib/python2.7/site-packages/sqlalchemy/sql/elements.py",
line 322, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params) File
"/var/www/topicdm/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 826, in _execute_clauseelement
compiled_sql, distilled_params File "/var/www/topicdm/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 893, in _execute_context
None, None) File "/var/www/topicdm/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 1159, in _handle_dbapi_exception
exc_info File "/var/www/topicdm/venv/lib/python2.7/site-packages/sqlalchemy/util/compat.py",
line 199, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb) File "/var/www/topicdm/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 887, in _execute_context
conn = self._revalidate_connection() File "/var/www/topicdm/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 242, in _revalidate_connection
"Can't reconnect until invalid " sqlalchemy.exc.StatementError: Can't reconnect until invalid transaction is rolled back (original
cause: InvalidRequestError: Can't reconnect until invalid transaction
is rolled back) u'SELECT topics.id AS topics_id, topics.topic_name AS
topics_topic_name, topics.topic_keywords AS topics_topic_keywords,
topics.topic_desc AS topics_topic_desc, topics.topic_domain AS
topics_topic_domain, topics.topic_alias AS topics_topic_alias,
topics.topic_topdomain AS topics_topic_topdomain, topics.topic_theme
AS topics_topic_theme, topics.user_id AS topics_user_id,
topics.topic_update AS topics_topic_update \nFROM topics \nWHERE
topics.topic_domain = %s \n LIMIT %s' [immutabledict({})]

flask python sqlalchemy

阿斯特拉塔 10 years, 1 month ago

报错的时候 topic_domain 的值也是正常的....

多多良小傘 answered 10 years, 1 month ago

Your Answer