I'm trying to write socket error handling (exactly err 111 - Connection Refused) but nothing is happening. Terminal print that Errno 111 occured but it's not doing anything with it:
import errno
try:
#do something
except socket.error, v:
errorcode=v[0]
if errorcode==errno.ECONNREFUSED:
print "Connection Refused"
else:
print("Running Application")
Traceback (most recent call last): File "Test.py", line 20, in s.connect((IP, PORT)) File "/usr/lib/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 111] Connection refused
Nothing else printed :/ What am I doing wrong ?
v
. Try debuggingv
or printv
to the console, maybev[0]
is not the error code. – bastelflpconnect
is going to want a socket and so all printing an error message does is push the exception to the caller when it tries to use the socket and has None. Now you've managed to swallow the exception, moved the fatal exception to somewhere else in the code, and handled nothing. – msw