From 19842f944558f2e3eb5a8d4d6bf35aefd400f97d Mon Sep 17 00:00:00 2001 From: mokaddem Date: Fri, 30 Aug 2019 11:05:43 +0200 Subject: [PATCH] fix: Catch if country does not have alpha_2 attribute - fix #119 --- helpers/geo_helper.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/helpers/geo_helper.py b/helpers/geo_helper.py index 6d29708..5fe678b 100644 --- a/helpers/geo_helper.py +++ b/helpers/geo_helper.py @@ -21,6 +21,7 @@ from phonenumbers import geocoder class InvalidCoordinate(Exception): pass + class Geo_helper: def __init__(self, serv_redis_db, cfg): self.serv_redis_db = serv_redis_db @@ -62,7 +63,12 @@ class Geo_helper: print(error) print("Please fix the above and try again.") sys.exit(126) - self.country_to_iso = { country.name: country.alpha_2 for country in pycountry.countries} + self.country_to_iso = {} + for country in pycountry.countries: + try: + self.country_to_iso[country.name] = country.alpha_2 + except AttributeError: + pass with open(self.PATH_TO_JSON) as f: self.country_code_to_coord = json.load(f)