Skip to content

Attempting to handle reconnections myself throws "socketio.exceptions.ConnectionError: Already connected" #773

Answered by miguelgrinberg
devkrxspl asked this question in Q&A
Discussion options

You must be logged in to vote

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:

while True:
    try:
        sio.connect(url)
    except Exception as e:
        print(e)
    else:
        sio.wait()

    print("Attempting to reconnect...");
    time.sleep(1)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by devkrxspl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #772 on August 24, 2021 18:57.