You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the javascript client now expects the rejected connection to provide a data.message in the returned packed. From python-socketio this would appear to be None, which raises the following error in the browser:
Cannot read property 'message' of undefined at Socket.onpacket (socket.js:258)
The python-socketio client doesnt seem to have this problem.
You can quickly reproduce this with a couple of snippets:
Server:
fromflaskimportFlaskfromflask_socketioimportSocketIOapp=Flask(__name__)
app.config["SECRET_KEY"] ="secret!"socketio=SocketIO(app, cors_allowed_origins="*")
@socketio.on("connect")defconnect(*args, **kwargs):
# reject all connections to testreturnFalseif__name__=="__main__":
socketio.run(app, host="0.0.0.0", port=8080)
Yes, it looks like I missed this. The new CONNECT_ERROR package is not freeform, it has to have the message and data fields in its payload. Instead of returning False, you can raise an exception as follows to make everything work:
@socketio.on("connect")defconnect(*args, **kwargs):
# reject all connections to testraiseConnectionRefusedError({'message': 'error message here'})
You can also add a data member to the dict including optional arguments that are passed in the error object in the client side.
I will figure out a way to map all the possible ways the server can reject a connection into valid CONNECT_ERROR packets.
@stufisher I have pushed an update with a fix for this problem. Can I ask you to install the master branch of the repo and verify if this fixes the problem for you?
Hi @miguelgrinberg, thanks for your quick reply and fix. That looks to be working for me, i can now see your Connection rejected by server in the client.
From digging around, it looks like rejecting connections in the latest python-socketio is not compatible with the latest javascript socket.io.client.
In this change:
socketio/socket.io-client@0939395#diff-f0e64910289a49966c99ceadaa5637404e3439ec0812a4bdb7003fe1e5a33d1cR253
the javascript client now expects the rejected connection to provide a
data.message
in the returned packed. From python-socketio this would appear to beNone
, which raises the following error in the browser:The python-socketio client doesnt seem to have this problem.
You can quickly reproduce this with a couple of snippets:
Server:
python client works -> connection failed message:
simple js client -> throws Cannot read property 'message' of undefined:
Versions:
and socket.io.client = 3.0.4
The text was updated successfully, but these errors were encountered: