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
self.run_application()
File "C:\Users\Z\anaconda3\envs\dash\lib\site-packages\geventwebsocket\handler.py", line 75, in run_application
self.run_websocket()
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.
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.
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: