Python 2.7: Unable to catch exception -
i have following code:
def distributemembersfile(members): node in members: node = node.strip() # strip trailing \n if node == socket.hostname(): # no need send file continue conn = none try: s = socket.socket(socket.af_inet, socket.sock_stream) s.connect((node, port)) # todo: can possibly update list of members here s.sendall('dwld') s.recv(4) except socket.error, msg: logging.info(msg) finally: if s: s.close()
now, question though s.connect() in try except socket.error block, exception not being caught. see following traceback on console:
s.connect((node, port)) file "<string>", line 1, in connect error: (111, 'connection refused')
interestingly, in other places have same try except socket.error block, , particular (connection refused) error caught as:
info (111, 'connection refused')
above printed logging.info function in except block. way see right catch exception use 'bare' except, not considered thing. also, found peculiar error on console not being presented
socket.error: (111, 'connection refused')
instead, says
error: (111. 'connection refused')
missing leading word 'socket'. reason behing exception not being caught?
Comments
Post a Comment