使用 gunicorn 和 nginx 处理请求时出错
Error handling request with gunicorn and nginx
我得到了 "Error handling request",但我真的无法将其归结为特定问题?
我正在使用 gunicorn+nginx,我的 gunicorn 设置是
gunicorn run:app -w 4 -b 0.0.0.0:8080 --workers=1 --timeout=300
这是错误信息
2015-10-14 21:27:11,287 DEBG 'myserver' stderr output:
[2015-10-14 21:27:11 +0000] [26725] [ERROR] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/sync.py", line 130, in handle
self.handle_request(listener, req, client, addr)
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/sync.py", line 171, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/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/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1566, in make_response
raise ValueError('View function did not return a response')
ValueError: View function did not return a response
任何人都可以提示我如何调试它吗?我对服务器使用没有太多经验......
谢谢
卡尔
tl;dr:这不是 gunicorn 或 nginx 的问题。您在 Flask 应用程序中的查看功能没有 return 响应。检查视图函数中的 return 语句,了解当您收到此错误时正在访问的任何路由。
从第
行开始
Traceback (most recent call last):
您可以看到 python 解释器生成的堆栈跟踪。 stack trace 显示导致代码失败点的嵌套函数序列。以我有限的经验,python 解释器堆栈跟踪可靠地将我引导到我的代码中的错误。
在你的例子中,最后一行:
ValueError: View function did not return a response
提供了有关错误的更多详细信息,应该可以让您很好地了解出了什么问题(您的视图函数没有 return 响应)。
从底部开始的下一行将显示触发错误的函数及其在代码中的确切位置:
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1566, in make_response
raise ValueError('View function did not return a response')
在这种情况下,错误是由 flask 源代码中的函数引发的,因此除非您对其进行了编辑,否则您可能不需要进行修复。根据跟踪末尾的特定 ValueError,我将直接转到我的视图函数。在 Flask 中,它可能看起来像这样(来自 Flask tutorial 的示例):
@app.route('/')
def show_entries():
cur = g.db.execute('select title, text from entries order by id desc')
entries = [dict(title=row[0], text=row[1]) for row in cur.fetchall()]
return render_template('show_entries.html', entries=entries)
在你的案例中,最后一行似乎是一个很好的起点,因为错误表明没有 returned。
我得到了 "Error handling request",但我真的无法将其归结为特定问题? 我正在使用 gunicorn+nginx,我的 gunicorn 设置是
gunicorn run:app -w 4 -b 0.0.0.0:8080 --workers=1 --timeout=300
这是错误信息
2015-10-14 21:27:11,287 DEBG 'myserver' stderr output:
[2015-10-14 21:27:11 +0000] [26725] [ERROR] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/sync.py", line 130, in handle
self.handle_request(listener, req, client, addr)
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/sync.py", line 171, in handle_request
respiter = self.wsgi(environ, resp.start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/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/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1566, in make_response
raise ValueError('View function did not return a response')
ValueError: View function did not return a response
任何人都可以提示我如何调试它吗?我对服务器使用没有太多经验...... 谢谢 卡尔
tl;dr:这不是 gunicorn 或 nginx 的问题。您在 Flask 应用程序中的查看功能没有 return 响应。检查视图函数中的 return 语句,了解当您收到此错误时正在访问的任何路由。
从第
行开始Traceback (most recent call last):
您可以看到 python 解释器生成的堆栈跟踪。 stack trace 显示导致代码失败点的嵌套函数序列。以我有限的经验,python 解释器堆栈跟踪可靠地将我引导到我的代码中的错误。
在你的例子中,最后一行:
ValueError: View function did not return a response
提供了有关错误的更多详细信息,应该可以让您很好地了解出了什么问题(您的视图函数没有 return 响应)。
从底部开始的下一行将显示触发错误的函数及其在代码中的确切位置:
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1566, in make_response
raise ValueError('View function did not return a response')
在这种情况下,错误是由 flask 源代码中的函数引发的,因此除非您对其进行了编辑,否则您可能不需要进行修复。根据跟踪末尾的特定 ValueError,我将直接转到我的视图函数。在 Flask 中,它可能看起来像这样(来自 Flask tutorial 的示例):
@app.route('/')
def show_entries():
cur = g.db.execute('select title, text from entries order by id desc')
entries = [dict(title=row[0], text=row[1]) for row in cur.fetchall()]
return render_template('show_entries.html', entries=entries)
在你的案例中,最后一行似乎是一个很好的起点,因为错误表明没有 returned。