Checking if the connection is successful

Hello, while my program was running, I suddenly got the connection error. How can I check that I have successfully connected to the API?

If the connection is successful, I want it to break the loop, and if there is an error, I want it to try to connect again after 5 seconds.

For this I wrote the following code;

import time
from binance.client import Client

while True:
    try:
        client = Client(config.api_key, config.api_secret)

        if len(client) > 0:
            break

    except Exception as e:
        print("Error:", e)
        time.sleep(5)
        pass

But because the client is an object, not a list, the len() function does not work. In addition, even if I leave the api key and api secret values blank, it does not give an error about establishing a connection.

Hi.
Though I’m not sure which library or package you are using, I guess this Client is to initiate some configuration. You have to send out the request to see if it works or not. If everything is fine, you should be able to see a response with http status code. Otherwise, it may hang till timeout.