python-socketio: "The client is using an unsupported version of the Socket.IO or Engine.IO protocols"
I use python flask as server frame React as front use socket.io-client 3.0.4 as client python-socketio 5.0.0 as server but l can not connect always “The client is using an unsupported version of the Socket.IO or Engine.IO protocols”
const socket = io("ws://127.0.0.1:8888");
// client-side
socket.on("connect", () => {
console.log(socket.id); // x8WIv7-mJelg7on_ALbx
});
from flask import Flask,abort,jsonify,request
from dataProcess import handleDataProcess
import socketio
import setting
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
app.config.from_object(setting.DevConfig)
sio = socketio.Server()
print({sio})
app.wsgi_app = socketio.WSGIApp(sio, app.wsgi_app)
@app.route('/api/dataprocess',methods=['POST'])
def dataProcess():
params = request.json.get('params')
result = handleDataProcess(params)
emit.SocketIO('dataprocesssuccess',{'test':11})
return jsonify(result)
@sio.event
def connect():
print("I'm connected!")
@sio.event
def connect_error():
print("The connection failed!")
@sio.event
def disconnect():
print("I'm disconnected!")
@sio.on('my_event')
def my_event(data):
print('Received data: ', data)
if __name__ == '__main__' :
app.run(host='127.0.0.1',port = 8888)
i want to konw why who can help me # #
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 53 (20 by maintainers)
Links to this issue
Commits related to this issue
- Upgrade Flask-SocketIO to 4.3.2 4.3.0 had a bug where it would upgrade to any version of python-socketio>=4.3.0. The issue is that python-socketio 5.x is incompatible with clients using JavaScript So... — committed to tiny-pilot/tinypilot by mtlynch 4 years ago
- Upgrade Flask-SocketIO to 4.3.2 (#370) 4.3.0 had a bug where it would upgrade to any version of python-socketio>=4.3.0. The issue is that python-socketio 5.x is incompatible with clients using JavaSc... — committed to tiny-pilot/tinypilot by mtlynch 4 years ago
- Fix dep sprawl between poetry and setup.py. Causing https://github.com/miguelgrinberg/python-socketio/issues/578 — committed to myoung34/tilty-dashboard by myoung34 2 years ago
- Remove main container padding. Fix client/server SocketIO version conflict. See https://github.com/miguelgrinberg/python-socketio/issues/578 — committed to Tymotex/Techsuite by Tymotex 2 years ago
I think I’ve found a solution as I’ve just had to deal with this issue. I believe it’s due to our lovely miguelgrinberg also updating the python-engineio just make sure you pull 3.13.2 if your using say 4.6.1. Otherwise 4.0.0 python-engineio will be pulled which is causing incompatibility issues.
Flask-SocketIO 4.x clients
If anyone’s running into this because their app had a dependency on Flask-SocketIO and it’s suddenly breaking, the issue is that there was a bug in the Flask-SocketIO setup.py prior to 4.3.2 that upgraded to any version of python-socketio >= 4.x. This was fine until python-socketio 5.x came out, which is not compatible with JavaScript socket.io clients on 1.x or 2.x.
@miguelgrinberg fixed this in this commit:
https://github.com/miguelgrinberg/Flask-SocketIO/commit/59740d3eb50395f44cfb786b85215b4ec9b795e9
He pushed that change to PyPi in Flask-SocketIO release 4.3.2.
The fix
For Flask-SocketIO 4.x clients, change your requirements.txt or setup.py to depend on Flask-SocketIO to 4.3.2.
Can confirm @zkquin observation. Helped me fixed my issue.
This is not a bug. The change to setup.py was made as soon as I knew that the next version of python-socketio was going to be backwards incompatible. The bug is in your application that does not pin all your dependencies.
The Correct Fix
The fix that you propose will just save you this time, but leaves you open to suffer from this problem again in the future.
The correct fix is this: once you get everything to work, run
pip freeze > requirements.txtto record the versions of all your dependencies (including indirect ones) in your requirements file and then you will never have this problem again.@mmajko What version of python-engineio do you have in your requirements.txt file? If you need to fix this, then uninstall python-socketio and python-engineio and then run the following:
And this will give you a working set up that works for v2 clients. Then, save your requirements (including the versions of the dependencies), so that this does not happen to you again next time!
What is the problem? Are you still getting complains about unsupported versions?
@ivan1016017 If the application works fine, then my guess is that you have another Socket.IO client that is an old version (in a different tab or browser) that is attempting to connect to this server.
@RAAKASH upgrade your client. Also read all the comments above.
pip install python-engineio==3.13.2 pip install python-socketio==4.6.1
let me know. do in your created environment only