python-socketio icon indicating copy to clipboard operation
python-socketio copied to clipboard

"The client is using an unsupported version of the Socket.IO or Engine.IO protocols"

Open kalaersun opened this issue 5 years ago • 53 comments

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 # #

kalaersun avatar Dec 08 '20 05:12 kalaersun

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.

miguelgrinberg avatar Dec 08 '20 09:12 miguelgrinberg

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

kalaersun avatar Dec 08 '20 10:12 kalaersun

What is the problem? Are you still getting complains about unsupported versions?

miguelgrinberg avatar Dec 08 '20 10:12 miguelgrinberg

What is the problem? Are you still getting complains about unsupported versions? i just don't know how to find whick version i should use

kalaersun avatar Dec 08 '20 10:12 kalaersun

Pick any line in that table and use those.

miguelgrinberg avatar Dec 08 '20 10:12 miguelgrinberg

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.

zkquin avatar Dec 08 '20 20:12 zkquin

Can confirm @zkquin observation. Helped me fixed my issue.

cmb87 avatar Dec 10 '20 07:12 cmb87

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.

mtlynch avatar Dec 10 '20 11:12 mtlynch

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.

miguelgrinberg avatar Dec 10 '20 19:12 miguelgrinberg

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.

Sorry, I'm not sure what you mean. If I pip install Flask-SocketIO==4.3.0 in a brand new virtualenv and run it against a 2.x JavaScript Socket.IO library, it will fail. That's a bug unless I'm misunderstanding the situation.

I'm not trying to cast blame. I was just trying to save other Flask-SocketIO clients time because it took me 30-40 minutes to understand what happened.

I agree with the technical decisions you've made, and I appreciate all your work on these libraries. I signed up as a Patreon sponsor after making my earlier comment to show my support.

once you get everything to work, run pip freeze > requirements.txt

Cool! I didn't realize pip offered this. That's a useful thing to know. Thanks for sharing!

mtlynch avatar Dec 10 '20 19:12 mtlynch

Sorry, I'm not sure what you mean. If I pip install Flask-SocketIO==4.3.0 in a brand new virtualenv and run it against a 2.x JavaScript Socket.IO library, it will fail. That's a bug unless I'm misunderstanding the situation.

Of course, but that version of Socket.IO is old. It was released at a point in time when it was not known that there would be a backwards incompatible version coming. If you are installing Flask-SocketIO today, you should install the current version, not an old version, and that would give you the correct dependencies, which you should save to a requirements file so that in the future, when this version becomes old you can restore a working environment. Today there is absolutely no reason to install that version in a new project.

miguelgrinberg avatar Dec 10 '20 20:12 miguelgrinberg

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.

Funcionou pra mim 0/ Estava a 3 dias procurando o motivo rsrs

thiagomoises avatar Dec 10 '20 23:12 thiagomoises

I still seem to be missing something? But what could it be?

[marcel@knaagbeest ~]$ pacman -Q python-engineio
python-engineio 4.0.0-1
[marcel@knaagbeest ~]$ pacman -Q python-socketio
python-socketio 5.0.2-1
[marcel@knaagbeest ~]$ pacman -Q python-flask-socketio
python-flask-socketio-git 4.3.2-1
[marcel@knaagbeest ~]$ curl https://x.x.x.x/socket.io/?transport=polling
"The client is using an unsupported version of the Socket.IO or Engine.IO protocols"

mischa85 avatar Dec 13 '20 03:12 mischa85

@mischa85 First of all, you can't pick and choose which versions of these packages you install, since different versions aren't always compatible. Install the most current version of flask-socketio and let the package manager bring the dependencies.

Second, what did you expect to happen? You are using curl (which is not a Socket.IO client) to connect to a Socket.IO service. The server is saying that the client cannot speak a known version of the Socket.IO/Engine.IO protocols, and that is exactly right.

miguelgrinberg avatar Dec 13 '20 10:12 miguelgrinberg

@miguelgrinberg Thanks for the quick answer and sorry for being a noob over here. I'm just trying to make another package working flask-nginx-rtmp-manager, which started acting up RuntimeError: Redis requires a monkey patched socket library to work with eventlet. Even on the original requirements.txt versions. Seriously spitting in the logs and even worse, restarting the streaming server every 30 secs.

That error was gone when I installed a 4.x version of python-eventio instead of 3.x, but that error is suddenly back now even on python-eventio 4.x so I'm back to square one.

On-topic: The javascript socketio 2.x was cached in my browser. Replacing it with js socketio 3.x which results in: Invalid session 9zs9Gte3KMTfprobAAAC But with the original monkey error back this is now the least of my problems.

mischa85 avatar Dec 13 '20 12:12 mischa85

@mischa85 Once again the error message is correct. These errors are intended to stop you from doing things wrong. Why are you not monkey patching? It is required for Redis to work.

miguelgrinberg avatar Dec 13 '20 12:12 miguelgrinberg

My requirements.txt file contains fixed version to 4.6.0, yet all my v2.x clients can't suddenly connect to the server after building the exact same version with no changes to list of dependencies, receiving 403 due to the "unsupported version" error.

...
python-socketio==4.6.0

You can't be serious, how am I supposed to downgrade the server now?

marianhlavac avatar Dec 13 '20 16:12 marianhlavac

@mischa85 Once again the error message is correct. These errors are intended to stop you from doing things wrong. Why are you not monkey patching? It is required for Redis to work.

It should be done by Gunicorn which is running and which is actually reporting the error, but is failing the monkey patching for some reason. I will file a bug report for the original error over there.

I will also try to reinstall everything and will report back over here if the socket.io error still appears.

For anybody wondering, I don't trust anything else than pacman to manage anything on my filesystem, even though an upgrade might have triggered all of this. Seeing the state of the Python ecosystem I have good reason not to use pip.

mischa85 avatar Dec 13 '20 16:12 mischa85

@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!

miguelgrinberg avatar Dec 13 '20 17:12 miguelgrinberg

@mmajko What version of python-engineio do you have in your requirements.txt file?

None. My code depends solely on the python-socketio package, which is installed according to the documentation.

... uninstall python-socketio and python-engineio and then run the following:

I'm running the builds isolated in Docker environment, there's no use to uninstall anything.

marianhlavac avatar Dec 13 '20 17:12 marianhlavac