socialwifi / RouterOS-api

Python API to RouterBoard devices produced by MikroTik.
MIT License
258 stars 98 forks source link

can't tell if the connection is success #66

Open SmartTransp opened 3 years ago

SmartTransp commented 3 years ago

I have try to check if the connection was OK and it's working by using this

connection = routeros_api.RouterOsApiPool(IP,user,pass) print (connection.connected ) api = connection.get.api() ---> I notice that here I get sometimes exceptions , but I can't catch it

but all the time I get "False"( when the router is online and also when the router is offline ) why ?

How can I check if the conneciton is "Alive"? how do read the "wrong pass" \ Timeout exception ?

did I miss something ?

argoA commented 2 years ago

You can use a try-except block to catch any exceptions.

try:
   conn = routeros_api.RouterOsApiPool(IP, USER, PASS)
   api = conn.get_api()
except Exception as e:
   print(e)