Dash-extensions: websockets. Getting error when I run examples

When I run the dash-extensions examples that use run_server() rather than app.run_server() such as websocket_push.py and websocket_update.py, I get the following error when I load the app.

Traceback (most recent call last):
  File "C:\Users\Z\anaconda3\envs\dash\lib\site-packages\gevent\pywsgi.py", line 999, in handle_one_response
  File "C:\Users\Z\anaconda3\envs\dash\lib\site-packages\geventwebsocket\handler.py", line 75, in run_application
  File "C:\Users\Z\anaconda3\envs\dash\lib\site-packages\geventwebsocket\handler.py", line 52, in run_websocket
    list(self.application(self.environ, lambda s, h, e=None: []))
  File "C:\Users\Z\anaconda3\envs\dash\lib\site-packages\flask\app.py", line 2088, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\Z\anaconda3\envs\dash\lib\site-packages\flask_sockets.py", line 40, in __call__
    handler, values = adapter.match()
  File "C:\Users\Z\anaconda3\envs\dash\lib\site-packages\werkzeug\routing.py", line 2030, in match
    raise WebsocketMismatch()
werkzeug.routing.WebsocketMismatch: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
2021-07-08T05:03:43Z {'REMOTE_ADDR': '::1', 'REMOTE_PORT': '59421', 'HTTP_HOST': 'localhost:5000', (hidden keys: 31)} failed with WebsocketMismatch

I’m on Windows 10, Python 3.9.5. I installed the Dash related modules just a few days ago so they should be the latest. Any suggestions on how to fix this would be appreciated. Thanks.

The examples were created on Ubuntu. I am not sure if the backend part of the examples works on Windows, but the component itself should.

Anyone have a suggestion on how to get

running on Windows 10?

By the way, dash-extensions was throwing an error because I didn’t have flask_sockets installed. I installed the latest version and that might not be compatible with dash-extensions.

@Emil : Should flask-sockets be a requirement?

I came across the same problem. The reason is that flask-sockets used in the Dash extension is not maintained anymore and does not work with Flask 2.0. One solution is to downgrade to Flask 1.1.4.

Another solution is to monkeypatch it by applying the fix used in several forks after the imports:

import flask_sockets

def add_url_rule(self, rule, _, f, **options):
self.url_map.add(flask_sockets.Rule(rule, endpoint=f, websocket=True))

flask_sockets.Sockets.add_url_rule = add_url_rule

Another solution could be to update the examples to use a websocket implementation that is maintained, e.g.