Discussion:
[Tutor] Exception Handling
Alan Gauld
2015-10-02 23:51:37 UTC
Permalink
socket.gaierror: [Errno 11004] getaddrinfo failed
...
ResolveHostname = socket.gethostbyname(name)
print(ResolveHostname)
newFile.write(ResolveHostname + "\n")
print(ResolveHostname)
newFile.write("No resolution available for %s" % (name) + "\n")
You are catching herror but your code is resulting in gaierror.

Add socket.gaierror to your except line.

except (socket.herror, socket.gaierror):
newFile.write("No resolution available for %s" % (name) + "\n")

see if that works
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Cameron Simpson
2015-10-03 03:49:13 UTC
Permalink
Post by Alan Gauld
socket.gaierror: [Errno 11004] getaddrinfo failed
...
ResolveHostname = socket.gethostbyname(name)
print(ResolveHostname)
newFile.write(ResolveHostname + "\n")
print(ResolveHostname)
newFile.write("No resolution available for %s" % (name) + "\n")
You are catching herror but your code is resulting in gaierror.
Add socket.gaierror to your except line.
newFile.write("No resolution available for %s" % (name) + "\n")
see if that works
Just a followon remark: always try to print the exception when you're not
certain of what it will be or what to do with it. So I'd augument Alan's code
like this:

except (socket.herror, socket.gaierror) as e:
newFile.write("No resolution available for %s: %s" % (name, e) + "\n")

Cheers,
Cameron Simpson <***@zip.com.au>
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Loading...