As far as I know, most of the errnos returned by python's exceptions are the same with the errnos in "linux/errno.h". But at sometimes, things are not like what I expect:
For example, when a socket connection throw a socket.timeout exception, the errno it returned should be 110, however, it's errno is always None:
try:
address = ('8.8.8.8', 12345)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
s.connect(address)
except EnvironmentError as e:
print e.errno # None
print e.strerror # "time out"
Secondly, when a address-related exception is throwed, the errno will be negative, but the errnos in linux/errno.h are between 1 and 133:
try:
address = ('xxxxxxx', 12345)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(address)
except socket.gaierror, v:
print v[0] # -5
In this case, will print -5.
I'm so confused of all of these errnos. :(
Only OSError and IOError carry an errno value. The socket.gaierror will return a getaddrinfo(3) error code. Other exceptions usually just carry strings. The codes are in the socket module. the -5 is socket.EAI_NODATA, which means "The specified network host exists, but does not have any network addresses defined".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With