Can someone help me on how I can catch this error?
import pygeoip
gi = pygeoip.GeoIP('GeoIP.dat')
print gi.country_code_by_name('specificdownload.com')
Traceback (most recent call last):
File "<module1>", line 14, in <module>
File "build\bdist.win-amd64\egg\pygeoip\__init__.py", line 447, in country_code_by_name
addr = self._gethostbyname(hostname)
File "build\bdist.win-amd64\egg\pygeoip\__init__.py", line 392, in _gethostbyname
return socket.gethostbyname(hostname)
gaierror: [Errno 11001] getaddrinfo failed
Well, let’s ask Python what type of exception that is:
Prints:
So we need to catch
socket.gaierror
, like so:Though there’s still the question of, what the heck is
gaierror
? Google turns up thesocket.gaierror
documentation, which says,So GAI Error = Get Address Info Error.