flask-uwsgi-websocket icon indicating copy to clipboard operation
flask-uwsgi-websocket copied to clipboard

generate a request context for all the WS handler exec environments

Open trbabb opened this issue 5 years ago • 1 comments

Inside of websocket handlers, the flask request context doesn't currently exist. This makes it difficult to do things like access cookies, and also breaks compatibility with other flask plugins (like flask-login, in my case, which pre-loads user information, and assumes the request context is valid).

In my own app, this seems to work. Looks like activity on this repo is low, but I thought I'd offer the PR in case it might be useful to other users of this repo & it makes sense to install unconditionally.

trbabb avatar Sep 25 '19 22:09 trbabb

Thanks for sharing this. This is something I've been looking for since the advice in the README to pass ws.environ to app.request_context() is wrong (out of date?).

However, when I try the MR for gevent, I get the following. I'm guessing something has had a breaking change since you authored the MR. Any suggestions?

Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
  File "/home/rosensama/.local/share/virtualenvs/mendoza-HQwqgdmM/lib/python3.9/site-packages/flask_uwsgi_websocket/_gevent.py", line 80, in wrapped_handler
    return handler(client, **args)
TypeError: 'gevent._gevent_cgreenlet.Greenlet' object is not callable
2020-12-28T22:12:14Z <Greenlet at 0x7fd9ddec6bf0: wrapped_handler> failed with TypeError

Flask 1.1.2 Flask-uWSGI-WebSocket 0.6.1 uWSGI 2.0.19.1 gevent 20.9.0

rosensama avatar Dec 28 '20 22:12 rosensama