どうすればsocket.error: [Errno 111] Connection refused
例外?
try:
senderSocket.send("Hello")
except ?????:
print "catch !"
allsocket.error
例外、およびerrno
属性が111に等しくない場合に再レイズします。または、より良いのは errno.ECONNREFUSED
代わりに定数:
import errno
from socket import error as socket_error
try:
senderSocket.send('Hello')
except socket_error as serr:
if serr.errno != errno.ECONNREFUSED:
# Not the error we are looking for, re-raise
raise serr
# connection refused
# handle here