ImportError: cannot import name 'run_with_reloader' from 'werkzeug.serving'
Asked Answered
S

4

11

I am getting the following error when I try to run the backend of my web application: ImportError: cannot import name 'run_with_reloader' from 'werkzeug.serving'. It is coming from within the \lib\site-packages\werkzeug\serving.py file. I think it has to do with the line from flask_socketio import SocketIO inside my server file. Any ideas?

Sain answered 13/4, 2022 at 1:59 Comment(0)
T
10

I had to downgrade Werkzeug and Flask to avoid this error. When Flask-SocketIO is involved, you may need to stick with older versions to avoid incompatibility issues with newer versions of Flask.

The combination that works for me is:

Flask-SocketIO==4.3.1
python-engineio==3.13.2
python-socketio==4.6.0
Flask==2.0.3
Werkzeug==2.0.3
Tombouctou answered 13/12, 2022 at 19:0 Comment(0)
S
3

This error has been addressed, so you are very likely using an old version of Flask-SocketIO. Once you upgrade the error should go away.

Scroll answered 15/4, 2022 at 15:17 Comment(6)
Is there anyway to continue using SocketIO version 4, A flutter package only supports version 3 or 4 socketio server. pub.dev/packages/socket_io_client :: error- The client is using an unsupported version of the Socket.IO or Engine.IO protocolsGiroux
Temporarily I manually installed package Werkzeug version below 2.1 to overcome this error. So that I can continue using SocketIO version 4.3.2.Giroux
The v3 and v4 versions are for the reference implementation in JavaScript, those versions are not related to versions of the Python server. The version mapping between JavaScript and Python are in the documentation: flask-socketio.readthedocs.io/en/latest/…Scroll
But using Flask-SocketIO version 5+ I get the unsupported version in client side error. Using Flask-SocketIO 4.3.2 I have no issues.Giroux
After updating python package you also need to update version of socket.io in frontend (usually index.html), according to the link posted above by @MiguelGrinberg . Worth adding this into answer, otherwise it sounds like pip install solves the problemAldana
work for me after upgrade the versionSloat
H
2

I needed to keep using flask-socketio v4 (for older socketio.js) and pinning to 2.0.x version of Werkzeug fixed this problem

--- a/python-flask-socketio-server/requirements.txt
+++ b/python-flask-socketio-server/requirements.txt
@@ -1,4 +1,5 @@
 flask
+Werkzeug==2.0.1
 flask-socketio==4.3.2
 # wheel should not be needed, but avoids pyyaml paho-mqtt bdist_wheel error
 wheel

Note: I also needed to tell pip to not use cached packages, or else it would still pull in problematic 2.1.x version to virtualenv that was being regenerated.

pip install --no-cache-dir -r requirements.txt
Hypocrisy answered 17/5, 2022 at 17:56 Comment(0)
W
0

Solution is to install the following Werkzeug version (Werkzeug-0.10.2.dev0dev-20220510) along with the following versions: [Tested in MacOS]

pip3 install Flask-SocketIO==4.3.1

pip3 install python-engineio==3.13.2

pip3 install python-socketio==4.6.0

pip3 install git+https://github.com/untitaker/werkzeug.git@reloader-perf

Wholehearted answered 10/5, 2022 at 12:29 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.