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)

Commits related to this issue

Most upvoted comments

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.

It’s exactly what the error says. The version of the Socket.IO client that you are using is incompatible with the version of the server. Either upgrade your client, or downgrade your server. The README of this repo has a table that shows you which JS and Python versions are compatible.

image socket.io-client 3.0.4 as client python-socketio 5.0.0 as server i use this two i don not konw where is the porblem

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.

there was a bug in the Flask-SocketIO setup.py

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.txt to 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:

pip install "python-socketio<5"

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.

Requirement already satisfied: Flask_SocketIO in ./venv/lib/python3.9/site-packages (from -r requirements.txt (line 13)) (5.0.0)
Requirement already satisfied: python-engineio in ./venv/lib/python3.9/site-packages (from -r requirements.txt (line 14)) (4.0.0)
Requirement already satisfied: python-socketio in ./venv/lib/python3.9/site-packages (from -r requirements.txt (line 15)) (5.0.3)

This is my current situation and it still throws the "the client is using an unsupported version of the SocketIO or EngineIO protocols

pip install python-engineio==3.13.2 pip install python-socketio==4.6.1

let me know. do in your created environment only