I'm trying to handle exceptions I have the following code:
conn = http.client.HTTPSConnection (site, timeout = 5)
When the waiting time exceeds What exception should I use?
try:
conn = http.client.HTTPSConnection(site, timeout=5)
conn.request("GET", "/")
except http.client.NotConnected as e:
cprint("%-30s %-50s %-10s %-30s %-20s" %(time.strftime("%c"),site, st,rs,elapse_time),'red')
I've never handled exceptions and I do not want to stop when a website does not respond within the timeout.
the code is as follows
while 1:
cantT=0
for site in SITES:
#prueba
#conn = urllib.request.urlopen(site)
#conn = httplib.HTTPConnection(site, timeout=10)
#Variables de conexion y estado
try:
conn = http.client.HTTPSConnection(site, timeout=5)
conn.request("GET", "/")
response = conn.getresponse()
rs = response.reason
st = str (response.status)
cantT+= 1
#se calcula el tiempo transcurido para el check
inicio = time.time()
elapse_time = str(time.time()-inicio)
if response.status == 200:
cprint("%-30s %-50s %-10s %-30s %-20s" %(time.strftime("%c"),site, st,rs,elapse_time),'green')
and in the documentation it is not that I say much. link