From 763f7077a1822061817a425a0d888d31f8949b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Tue, 9 Dec 2014 01:29:15 -0500 Subject: [PATCH 1/2] avoid crashing on undetermined locations this works around what is probably a bug in pygeoip: 01:21:44 <@anarcat> .ip 10.0.0.1 01:21:49 AttributeError: 'NoneType' object has no attribute 'get' (file "/usr/local/lib/python3.4/dist-packages/pygeoip/__init__.py", line 491, in country_name_by_addr) it seems that, even internally, pygeoip doesn't handle very well addresses that have no location defined... this patch should fix the problem in willie until it is fixed upstream. --- ip.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ip.py b/ip.py index ca823cb8c4..0a9f77c013 100644 --- a/ip.py +++ b/ip.py @@ -106,7 +106,10 @@ def ip(bot, trigger): gi_org = pygeoip.GeoIP(geolite_ASN_filepath) host = socket.getfqdn(query) response = "[IP/Host Lookup] Hostname: %s" % host - response += " | Location: %s" % gi_city.country_name_by_name(query) + try: + response += " | Location: %s" % gi_city.country_name_by_name(query) + except AttributeError: + pass region_data = gi_city.region_by_name(query) try: From ddd1f4bcd511e51b73e4b5123c699b734965bdcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Tue, 9 Dec 2014 09:37:39 -0500 Subject: [PATCH 2/2] keep the Location tag even if unknown so display is more consistent --- ip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ip.py b/ip.py index 0a9f77c013..cc3524b76b 100644 --- a/ip.py +++ b/ip.py @@ -109,7 +109,7 @@ def ip(bot, trigger): try: response += " | Location: %s" % gi_city.country_name_by_name(query) except AttributeError: - pass + response += ' | Location: Unknown' region_data = gi_city.region_by_name(query) try: