now it works once if connected successfully, but if exception is met, it doesn't retry as I wish, just throwing:
Will retry: [Errno 111] Connection refused
It should return False if all attempts weren't successful and True if at least one returned an answer
Seems there's something complicated with 'while' needed, like
for attempt in range(attempts) and while True
Here's my code:
attempts = 10
for attempt in range(attempts):
try:
conn = httplib.HTTPConnection("server:80", timeout=5)
conn.request("GET","/url")
r = conn.getresponse()
except socket.error, serr:
print("Will retry: %s" % serr)
conn.close()
else:
print("OK")
finally:
return False
I tried also:
for attempt in range(attempts):
while True:
try:
The same result...