Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

websocket_push example fails #114

Closed
harisbal opened this issue Dec 23, 2021 · 4 comments
Closed

websocket_push example fails #114

harisbal opened this issue Dec 23, 2021 · 4 comments

Comments

@harisbal
Copy link

Hello,
I'm trying to run the websocket_push.py example but I encounter two issues:

  1. flask_sockets is required to run the process (although missing from requirements.txt).
  2. After installing flask_sockets I get this:
werkzeug.routing.WebsocketMismatch: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
2021-12-23T23:51:28Z {'REMOTE_ADDR': '::1', 'REMOTE_PORT': '32888', 'HTTP_HOST': 'localhost:5000', (hidden keys: 31)} failed with WebsocketMismatch

Do I need to do some preparation work prior to running the example?

@emilhe
Copy link
Owner

emilhe commented Dec 24, 2021

  1. The is expected behaviour. I didn't include that package in requirements, as it is only use in the example itself.
  2. That shouldn't be necessary, it should just work out of the box. What OS and Python version are you on? I haven't seen that error before (I tested on Ubuntu).

@harisbal
Copy link
Author

harisbal commented Dec 24, 2021

Python 3.9.5
Ubuntu 21.04
I'm running the script in a venv based on the requirements.txt and the additional flask_sockets.
I believe the error comes from the flask_socket library. See full traceback below:

Traceback (most recent call last):
  File "/home/harisbal/Programming/dash-websocket/.venv/lib/python3.9/site-packages/gevent/pywsgi.py", line 999, in handle_one_response
    self.run_application()
  File "/home/harisbal/Programming/dash-websocket/.venv/lib/python3.9/site-packages/geventwebsocket/handler.py", line 75, in run_application
    self.run_websocket()
  File "/home/harisbal/Programming/dash-websocket/.venv/lib/python3.9/site-packages/geventwebsocket/handler.py", line 52, in run_websocket
    list(self.application(self.environ, lambda s, h, e=None: []))
  File "/home/harisbal/Programming/dash-websocket/.venv/lib/python3.9/site-packages/flask/app.py", line 2091, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/harisbal/Programming/dash-websocket/.venv/lib/python3.9/site-packages/flask_sockets.py", line 40, in __call__
    handler, values = adapter.match()
  File "/home/harisbal/Programming/dash-websocket/.venv/lib/python3.9/site-packages/werkzeug/routing.py", line 2039, in match
    raise WebsocketMismatch()
werkzeug.routing.WebsocketMismatch: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
2021-12-24T11:12:56Z {'REMOTE_ADDR': '::1', 'REMOTE_PORT': '51696', 'HTTP_HOST': 'localhost:5000', (hidden keys: 31)} failed with WebsocketMismatch

P.S
A similar issue can be found here

@harisbal
Copy link
Author

harisbal commented Dec 24, 2021

I figured it out. Using Werkzeug==1.0.1 solved the issue. However, many other dependencies had to be downgraded too (e.g. Flask 2 cannot be used). This issue suggests a workaround enabling flask-sockets to use newer versions of Flask and Werkzeug.
I understand that the implications may be significant but I was wondering whether flask-socketio could be used instead of flask_sockets (which seems like an abandoned project)?

@emilhe
Copy link
Owner

emilhe commented Dec 25, 2021

I believe so. This was just a small example to demo the usage that I put together when the component was implemented. I would be happy to look at a PR, either with a comment on dependencies needed or a more up to date example.

@emilhe emilhe closed this as completed Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants