appliedsec/pygeoip — pull request #6 by vatsan (2012-04-11 21:45:51+00:00)
Title: Fixed bug in __init__.py line 294 (NoneType not iterable).

I have a wrapper :

class GeoIP:
def __init__(self):
self.geoip = pygeoip.GeoIP('')
def getCountry(self,ip):
return self.geoip.country_code_by_addr(ip)

When I invoke it like so :
gp = GeoIP()
gp.getCountry('10.20.30.40')

I get :

Traceback (most recent call last):
File "", line 1, in
File "", line 5, in getCountry
File "build/bdist.linux-x86_64/egg/pygeoip/__init__.py", line 429, in country_code_by_addr

File "build/bdist.linux-x86_64/egg/pygeoip/__init__.py", line 587, in region_by_addr

File "build/bdist.linux-x86_64/egg/pygeoip/__init__.py", line 294, in _get_region

TypeError: argument of type 'NoneType' is not iterable

The error is in line 294 of __init__.py that assumed that "rec" will not be None (which doesn't seem to be the case with many IPs i tested).