From 25ae2f0eea4ba4fd41a7d82ac65529fee1d5d6a1 Mon Sep 17 00:00:00 2001 From: ebdavison <549431+ebdavison@users.noreply.github.com> Date: Tue, 11 Apr 2023 11:37:47 -0500 Subject: [PATCH] fix for issue #27 Despite the fact that it is a problem with GeoIP lookup, it should not crash the code. --- mha/server.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mha/server.py b/mha/server.py index 4177e3d..c35087d 100644 --- a/mha/server.py +++ b/mha/server.py @@ -34,12 +34,15 @@ def getCountryForIP(line): if ip: ip = ip[0] # take the 1st ip and ignore the rest if IP(ip).iptype() == 'PUBLIC': - r = reader.country(ip).country - if r.iso_code and r.name: - return { - 'iso_code': r.iso_code.lower(), - 'country_name': r.name - } + try: + r = reader.country(ip).country + if r.iso_code and r.name: + return { + 'iso_code': r.iso_code.lower(), + 'country_name': r.name + } + except: + pass return dict(country=getCountryForIP)