我开始使用我的应用程序
gunicorn --worker-class eventlet -w 1 server:app --bind="127.0.0.1:5000"
并且当将 Flack-SocketIO 用于 websockets 时,我经常收到 Gunicorn 没有从函数正确返回的错误
[2016-01-30 10:20:53 -0800] [7330] [ERROR] Error handling request
Traceback (most recent call last):
File "/Users/brianclark/Desktop/Projects/HDP/application/api/venv/lib/python2.7/site-packages/gunicorn/workers/async.py", line 52, in handle
self.handle_request(listener_name, req, client, addr)
File "/Users/brianclark/Desktop/Projects/HDP/application/api/venv/lib/python2.7/site-packages/gunicorn/workers/async.py", line 114, in handle_request
resp.close()
File "/Users/brianclark/Desktop/Projects/HDP/application/api/venv/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 423, in close
self.send_headers()
File "/Users/brianclark/Desktop/Projects/HDP/application/api/venv/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 316, in send_headers
tosend = self.default_headers()
File "/Users/brianclark/Desktop/Projects/HDP/application/api/venv/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 297, in default_headers
elif self.should_close():
File "/Users/brianclark/Desktop/Projects/HDP/application/api/venv/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 230, in should_close
if self.status_code < 200 or self.status_code in (204, 304):
AttributeError: 'Response' object has no attribute 'status_code'
关于我可以用来解决这个问题的配置的任何建议还是一个错误?
@bclark8923你有任何可以帮助重现问题的应用程序吗?
是的! 你想我做什么?
周一,2016年3月28日,伯努瓦Chesneau [email protected]写道:
@bclark8923 https://github.com/bclark8923你有什么申请吗
这可以帮助重现问题吗?—
你收到这个是因为你被提到了。
直接回复此邮件或在 GitHub 上查看
https://github.com/benoitc/gunicorn/issues/1210#issuecomment -202484667
谢谢,
布莱恩·克拉克
(248) 990 5616
www.hdphealth.com
在 Facebook https://facebook.com/bclark8923和 Twitter 上认识我
https://twitter.com/blaurenceclark!
@bclark8923如果它可以流式传输,那么最终我可以在测试中包含一些有助于:)
另外你用的是哪个版本的gunicorn?
是的,请! 给我发电子邮件
很快
周一,2016年3月28日,伯努瓦Chesneau [email protected]写道:
@bclark8923 https://github.com/bclark8923 如果可以流式传输
最终,我可以在测试中包含一些有帮助的部分:)另外你用的是哪个版本的gunicorn?
—
你收到这个是因为你被提到了。
直接回复此邮件或在 GitHub 上查看
https://github.com/benoitc/gunicorn/issues/1210#issuecomment -202492005
谢谢,
布莱恩·克拉克
(248) 990 5616
www.hdphealth.com
在 Facebook https://facebook.com/bclark8923和 Twitter 上认识我
https://twitter.com/blaurenceclark!
使用版本 19.4.5
我有同样的问题。 我正在使用 gunicorn 版本 18.0。
任何修复可用吗?
如果有人有 z 代码来重现它,那会有所帮助:)
@benoitc - 这是有道理的.. ;-)
下周我会解决一些问题并通知你!
可能有些东西需要返回gunicorn.workers.async.ALREADY_HANDLED
或者 gunicorn 会在应用程序从其 WSGI 处理程序返回时尝试记录请求。 相反,Gunicorn 需要知道请求现在完全由应用程序处理。
“examples/websocket”目录中的两个示例都从它们的 WSGI 处理程序返回这个常量。
@benoitc - 重现错误的示例是否有助于您找到错误? 我可以提供任何其他帮助来帮助解决这个问题吗?
@kramer65是的,我重现了错误。
所以 Gunicorn 是一个纯 WSGI 引擎,并且期待一个包含状态的 WSGI 响应:
https://github.com/benoitc/gunicorn/blob/master/gunicorn/http/wsgi.py#L242
(与此代码相关:https://github.com/benoitc/gunicorn/blob/master/gunicorn/workers/async.py#L103-L119)
正如@tilgovi所说,您可以通过返回 ALREADY_HANDLED 来绕过来自 gunicorn 的响应处理
就我阅读的 flash socketio 代码而言,它正在将烧瓶应用程序包装在socketio.Middleware
,它本身从engineio.middleware.Middleware
继承:
https://github.com/miguelgrinberg/python-engineio/blob/master/engineio/middleware.py
如果找到路径,则返回 wsgi 应用程序或它们自己的处理程序:
https://github.com/miguelgrinberg/python-engineio/blob/master/engineio/middleware.py#L45 -L52
所以它在 websocket 路径上返回socketio.Server.handle_request
:
https://github.com/miguelgrinberg/Flask-SocketIO/blob/master/flask_socketio/__init__.py#L144
它本身返回engineio.Server.handle_request
(这个项目中有很多循环 deps ......):
https://github.com/miguelgrinberg/python-engineio/blob/master/engineio/server.py#L184
此时似乎socket.handle_get_request
或socket. handle_post_request
设置状态:
https://github.com/miguelgrinberg/python-engineio/blob/master/engineio/socket.py#L69 -L96
然后这里可能会发生错误:
https://github.com/miguelgrinberg/python-engineio/blob/master/engineio/server.py#L251 -L252
因为它可以在没有设置状态或任何东西的情况下返回响应。 我可以看到升级使用与我们的示例相同的 websocket 对象:
https://github.com/benoitc/gunicorn/blob/master/examples/websocket/websocket.py
我认为,而不是在这里返回最终的r
:
https://github.com/miguelgrinberg/python-engineio/blob/master/engineio/server.py#L251 -L252
它可能应该像那里一样返回ALREADY_HANDLED
:
https://github.com/benoitc/gunicorn/blob/master/examples/websocket/websocket.py#L115
无论如何只是猜测,因为该代码很难阅读。 希望它会有所帮助。
@kramer65 无论如何让我知道这张票的状态:)
如果你能解决这个问题,那就太好了。 我在我的作品中运行flask-socketio
和 gunicorn 并且不想丢失数据。
我遇到了类似的问题,想知道是否有关于此问题的任何消息?
@benoitc - 你认为上面@miguelgrinberg提出的建议(让 Gunicorn 识别 eventlet 的 ALREADY_HANDLED 常量以及它自己的常量并以相同的方式处理它)是个好主意吗?
@kramer65如果你能找到一种方法来干净地添加支持,我认为 eventlet 工作人员处理它是有意义的。
现在处理这个问题的逻辑有点隐藏在gunicorn.workers.async.AsyncWorker#handle_request
但也许可以通过 eventlet 工作人员可以覆盖的静态属性间接处理,或者通过调用实例方法来检查任何工作人员已经处理的情况-可能存在的特定逻辑,基类现在这样做。
@tilgovi - 你给我发消息已经有一段时间了,但我还是想回复一下。 问题是我在这方面可以做的事情已经达到了我的极限。 我真的不知道如何继续解决这个问题。
与此同时,我的日志中充满了如下所示的错误消息,所以我完全有理由投入一些精力来解决这个问题。 我只是不完全了解问题的确切原因是什么,更不用说我了解如何解决这个问题了。
如果有人想联系我,我很乐意讨论这个问题,然后我可能会比现在提供更多帮助。
2016-08-23 08:07:16 [2185] [ERROR] Error handling request
Traceback (most recent call last):
File "/var/www/imd/venv/local/lib/python2.7/site-packages/gunicorn/workers/async.py", line 45, in handle
self.handle_request(listener, req, client, addr)
File "/var/www/imd/venv/local/lib/python2.7/site-packages/gunicorn/workers/async.py", line 102, in handle_request
resp.close()
File "/var/www/imd/venv/local/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 369, in close
self.send_headers()
File "/var/www/imd/venv/local/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 284, in send_headers
tosend = self.default_headers()
File "/var/www/imd/venv/local/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 265, in default_headers
elif self.should_close():
File "/var/www/imd/venv/local/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 198, in should_close
if self.status_code < 200 or self.status_code in (204, 304):
AttributeError: 'Response' object has no attribute 'status_code'
有没有修好?.....
@qwexvf - 不幸的是我没有。 我的日志仍然充满错误。 :-(
其他人?
@kramer65我明白了。 我已经等了很久了,如果有人有修复,请与我们分享! 谢谢!
任何更新?
我确信有更简洁的方法来解决这个问题,但至少这是一个开始。
@stefaang谢谢我想试试!
何时会在 PyPI 上发布此修复程序?
明天
在周五,2017年2月17日16:46时,埃迪[email protected]写道:
何时会在 PyPI 上发布此修复程序?
—
您收到此消息是因为您修改了打开/关闭状态。直接回复本邮件,在GitHub上查看
https://github.com/benoitc/gunicorn/issues/1210#issuecomment-280685264 ,
或静音线程
https://github.com/notifications/unsubscribe-auth/AAA4ogTRMF7EfR25G6gLrktOdh_iA4Ciks5rdcDYgaJpZM4HbcdP
.
已经发布了吗?
@benoitc关于推送到 pypi 的更新有任何消息吗?
@defionscode我将在星期四早上(明天)发布。
非常好,谢谢
在星期三,2017年2月22日在上午11时54伯努瓦Chesneau [email protected]
写道:
@defionscode https://github.com/defionscode我会在
星期四早上(明天)。—
你收到这个是因为你被提到了。
直接回复本邮件,在GitHub上查看
https://github.com/benoitc/gunicorn/issues/1210#issuecomment-281729992 ,
或静音线程
https://github.com/notifications/unsubscribe-auth/AEcrYp6QfVpWXhG14f4M-lPDHMn0cFncks5rfGhWgaJpZM4HbcdP
.
是否已发布此修复程序?
@Decker108状态由https://github.com/benoitc/gunicorn/issues/1471跟踪。 将于今天发布...
使用最新版本的 gunicorn 19 和 20,这个错误仍然发生在我这边。 应该修复@benoitc吗?
最有用的评论
@kramer65我明白了。 我已经等了很久了,如果有人有修复,请与我们分享! 谢谢!