Using Python 2.2.2,
I want to catch all exceptions from "socket.gethost byaddr(ip)"
From IDLE, I can generate:[color=blue][color=green][color=darkred]
>>> socket.gethostb yaddr('1.2')[/color][/color][/color]
Traceback (most recent call last):
File "<pyshell#2 8>", line 1, in ?
socket.gethostb yaddr('1.2')
herror: (11004, 'host not found') <=== what I want when I catch
When I run this code:
try:
hostname, aliases, hostip = socket.gethostb yaddr(ip)
return (hostip, hostname)
except:
print sys.exc_info()
print sys.exc_type
return
The "print sys.exc_info()" gives-
(<class socket.herror at 0x00AE7AC0>,
<socket.herro r instance at 0x00C725C0>,
<traceback object at 0x00C73920>)
And the "print sys.exc_type" gives-
socket.herror
How do I get the "(11004, 'host not found')" part?
More importantly, where is the answer documented that I should
have looked?
Frank
I want to catch all exceptions from "socket.gethost byaddr(ip)"
From IDLE, I can generate:[color=blue][color=green][color=darkred]
>>> socket.gethostb yaddr('1.2')[/color][/color][/color]
Traceback (most recent call last):
File "<pyshell#2 8>", line 1, in ?
socket.gethostb yaddr('1.2')
herror: (11004, 'host not found') <=== what I want when I catch
When I run this code:
try:
hostname, aliases, hostip = socket.gethostb yaddr(ip)
return (hostip, hostname)
except:
print sys.exc_info()
print sys.exc_type
return
The "print sys.exc_info()" gives-
(<class socket.herror at 0x00AE7AC0>,
<socket.herro r instance at 0x00C725C0>,
<traceback object at 0x00C73920>)
And the "print sys.exc_type" gives-
socket.herror
How do I get the "(11004, 'host not found')" part?
More importantly, where is the answer documented that I should
have looked?
Frank
Comment