I am trying to read a status from four web servers that monitor fluid tanks with an HTTP connection. It is not unusual for one or more of these servers to not be present, but that's okay, I just want to record a timeout error and continue to the other servers and get their status. I cannot figure out how to handle the timeout when it occurs? And always open to any other critique on this code... I'm brand new to Python.
# Fluid tank Reader
import http.client
activeTanks = 4;
myTanks=[100,100,100,100]
for tank in range(0,activeTanks):
tankAddress = ("192.168.1.4"+str(tank))
conn = http.client.HTTPConnection(tankAddress, timeout=1)
## How do I handle the exception and finish the For Loop?
conn.request("GET", "/Switch=Read")
r1 = conn.getresponse()
conn.close()
myTanks[tank] = int(r1.read().decode('ASCII').split("...")[1])
print(myTanks) # this will pass data back to a main loop later