miguelgrinberg / python-socketio

Python Socket.IO server and client
MIT License
4.01k stars 588 forks source link

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

Closed kalaersun closed 3 years ago

kalaersun commented 3 years ago

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

ivan1016017 commented 2 years ago

Hello @miguelgrinberg. I am facing the same issue despite the fact that I am using the following requirements.txt

Flask==1.0.2
Flask-Login==0.4.1
Flask-Session==0.3.1
Flask_SocketIO
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.0
python-engineio
python-socketio
six==1.11.0
Werkzeug==0.14.1
kafka-python

and the cdnjs

<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.1.2/socket.io.js" integrity="sha512-YybopSVjZU0fe8TY4YDuQbP5bhwpGBE/T6eBUEZ0usM72IWBfWrgVI13qfX4V2A/W7Hdqnm7PIOYOwP9YHnICw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

My toy application works fine, but the message

The client is using an unsupported version of the Socket.IO or Engine.IO protocols (further occurrences of this error will be logged with level INFO)

does not disappear.

If I use pip list, I get

bidict          0.22.0
click           8.1.3
colorama        0.4.4
Flask           1.0.2
Flask-Login     0.4.1
Flask-Session   0.3.1
Flask-SocketIO  5.2.0
itsdangerous    1.1.0
Jinja2          2.10
kafka-python    2.0.2
MarkupSafe      1.1.0
pip             22.0.4
pyspark         3.1.3
python-engineio 4.3.2
python-socketio 5.6.0
setuptools      62.1.0
six             1.11.0
Werkzeug        0.14.1
wheel           0.37.1

that follows the table just described in the previous comments made by kalaersun.

miguelgrinberg commented 2 years ago

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

hemanth-reckonsys commented 1 year ago

same issue, emitting event from client not working, from html connect and disconnect is working but not logged_in python-engineio==4.3.4 python-socketio==5.7.2

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <ul id="messages"></ul>

    <button id="disconnect">disconnect</button>
    <button id="connect">connect</button>
    <button id="emit">emit</button>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.1.3/socket.io.js"
       ></script>
    <script>
        var socket = io.connect('http://localhost:4444');

        $('#disconnect').click(function () {
            socket.disconnect();
        });
        socket.on('connect', function (msg) {
            console.log("client connected to server", msg);
            // socket.('logged_in', {"user_id":"Sdfgh"});

        });
        $('#emit').click(function () {
            a = socket.emit("logged_in", {"user_id":"jkl"});
            console.log("emitted", a);

        });
        socket.on("disconnect", function () {
            console.log("client disconnected from server");
        });
        socket.on("status", function (msg) {
            console.log("status", msg);
        });

    </script>
</body>

</html>

mgrr = RedisManager("redis://localhost:6379/0)

sio = Server( client_manager=mgrr, cors_allowed_origins="*", ping_interval=25, ping_timeout=120, )

@sio.event def connect(sid): print("I'm connected!")

@sio.event def logged_in(sid, data): print("logged_in", sid)

def handle(self, *args, **kwargs):
        eventlet.monkey_patch()
        app = WSGIApp(sio)
        port = int("4444")
        eventlet.wsgi.server(eventlet.listen(("", port)), app)
127.0.0.1 - - [13/Feb/2023 14:32:31] "GET /socket.io/?EIO=4&transport=websocket&sid=G7hDIo0bW1OXeCXPAAAA HTTP/1.1" 200 0 302.412260
(7886) accepted ('127.0.0.1', 48736)
127.0.0.1 - - [13/Feb/2023 14:32:33] "GET /socket.io/?EIO=4&transport=polling&t=OPBCHP7 HTTP/1.1" 200 314 0.000491
(7886) accepted ('127.0.0.1', 48742)
127.0.0.1 - - [13/Feb/2023 14:32:33] "POST /socket.io/?EIO=4&transport=polling&t=OPBCHPG&sid=SO9hFLyf-ADDC7B4AAAC HTTP/1.1" 200 202 0.000544
(7886) accepted ('127.0.0.1', 48754)
127.0.0.1 - - [13/Feb/2023 14:32:33] "GET /socket.io/?EIO=4&transport=polling&t=OPBCHPI&sid=SO9hFLyf-ADDC7B4AAAC HTTP/1.1" 200 216 0.000342
127.0.0.1 - - [13/Feb/2023 14:32:33] "GET /socket.io/?EIO=4&transport=polling&t=OPBCHPV&sid=SO9hFLyf-ADDC7B4AAAC HTTP/1.1" 200 216 0.000223