This question will expand on: Best way to open a socket in Python
When opening a socket how can I test to see if it has been established, and that it did not timeout, or generally fail.
Edit: I tried this:
try: s.connect((address, '80')) except: alert('failed' + address, 'down')
but the alert function is called even when that connection should have worked.
It seems that you catch not the exception you wanna catch out there 🙂
if the
sis asocket.socket()object, then the right way to call.connectwould be:Always try to see what kind of exception is what you’re catching in a try-except loop.
You can check what types of exceptions in a socket module represent what kind of errors (timeout, unable to resolve address, etc) and make separate
exceptstatement for each one of them – this way you’ll be able to react differently for different kind of problems.