suClick
suClick

Reputation: 996

When a socket error occur, how to get its errorcode from the exception?

Codes like this:

import socket, sys

try:
    address = ('127.0.0.1', 31500)  
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  
    s.connect(address)  
except Exception:
    errType, errValue, errTraceback = sys.exc_info()
    # or
    # handle the Exception it throw out ?

What I want to get is the errcode like 10060 which means connection time out, thanks for any help :)

Upvotes: 0

Views: 946

Answers (1)

nneonneo
nneonneo

Reputation: 179602

Use

except EnvironmentError as e:
    print e.errno

Upvotes: 2

Related Questions