From 3a622278c1af700a04ec2eb6f3e52ab9a5e4d87f Mon Sep 17 00:00:00 2001 From: Francisco Gutierrez Date: Thu, 12 Feb 2015 12:22:14 -0800 Subject: [PATCH] return {} instead of None when record not found country_name_by_addr(addr) fails when the record is not found: /usr/local/lib/python2.7/dist-packages/pygeoip/__init__.pyc in country_name_by_addr(self, addr) 489 return const.COUNTRY_NAMES[country_id] 490 elif self._databaseType in const.CITY_EDITIONS: --> 491 return self.record_by_addr(addr).get('country_name') 492 else: 493 message = 'Invalid database type, expected Country or City' AttributeError: 'NoneType' object has no attribute 'get' In a previous version (0.2.6) that doesn't fail when a record is not found record_by_addr(addr) returns {} instead of None. --- pygeoip/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygeoip/__init__.py b/pygeoip/__init__.py index 93b5c14..cfbbfad 100644 --- a/pygeoip/__init__.py +++ b/pygeoip/__init__.py @@ -546,7 +546,7 @@ def record_by_addr(self, addr): ipnum = util.ip2long(addr) rec = self._get_record(ipnum) if not rec: - return None + return {} return rec