Attempting to handle reconnections myself throws "socketio.exceptions.ConnectionError: Already connected" #773
-
When trying to handle reconnections myself, it always throws a Code: @sio.event
def disconnect():
print("Connection lost.");
try:
sio.connect('url');
except:
print("Reconnection attempt failed.");
while (True):
try:
sio.connect('url');
break;
except Exception as e:
print(e)
print("Attempting to reconnect...");
time.sleep(1); (I've also already set |
Beta Was this translation helpful? Give feedback.
Answered by
miguelgrinberg
Aug 24, 2021
Replies: 1 comment
-
You can't issue a connection from an even handler. You can use a for-loop in the top level of your script, combined with the while True:
try:
sio.connect(url)
except Exception as e:
print(e)
else:
sio.wait()
print("Attempting to reconnect...");
time.sleep(1) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
devkrxspl
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can't issue a connection from an even handler. You can use a for-loop in the top level of your script, combined with the
sio.wait()
method. Something like this: