From a4bdf6e21e6819621817e151b8911d5016034f74 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Thu, 27 Jun 2019 09:00:38 +0200 Subject: [PATCH 1/2] fix: [geohelper] Prevent crash if country not defined in the geo response --- helpers/geo_helper.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/helpers/geo_helper.py b/helpers/geo_helper.py index a61d4c4..08763be 100644 --- a/helpers/geo_helper.py +++ b/helpers/geo_helper.py @@ -120,7 +120,8 @@ class Geo_helper: if not self.coordinate_list_valid(coord_list): raise InvalidCoordinate("Coordinate do not match EPSG:900913 / EPSG:3785 / OSGEO:41001") self.push_to_redis_zset(self.keyCategCoord, json.dumps(ordDic)) - self.push_to_redis_zset(self.keyCategCountry, rep['full_rep'].country.iso_code) + iso_code = rep['full_rep'].country.iso_code if rep['full_rep'].country.iso_code is not None else rep['full_rep'].registered_country.iso_code + self.push_to_redis_zset(self.keyCategCountry, iso_code) ordDic = OrderedDict() #keep fields with the same layout in redis ordDic['categ'] = categ ordDic['value'] = supposed_ip @@ -203,6 +204,9 @@ class Geo_helper: print("To test for support: echo \"help GEOADD\"| redis-cli") self.logger.debug('Added to redis: keyname={}, lon={}, lat={}, content={}'.format(keyname, lon, lat, content)) def push_to_redis_zset(self, keyCateg, toAdd, endSubkey="", count=1): + if not isinstance(toAdd, str): + self.logger.warning(f'Can\'t add to redis, element is not of type String. {type(toAdd)}') + return now = datetime.datetime.now() today_str = util.getDateStrFormat(now) keyname = "{}:{}{}".format(keyCateg, today_str, endSubkey) From 6b064732fdc3cad40bfa053637b845c4c267d31e Mon Sep 17 00:00:00 2001 From: mokaddem Date: Thu, 27 Jun 2019 10:39:03 +0200 Subject: [PATCH 2/2] fix: try another mean to forward the country to the client --- helpers/geo_helper.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/helpers/geo_helper.py b/helpers/geo_helper.py index 08763be..20bed1a 100644 --- a/helpers/geo_helper.py +++ b/helpers/geo_helper.py @@ -121,6 +121,7 @@ class Geo_helper: raise InvalidCoordinate("Coordinate do not match EPSG:900913 / EPSG:3785 / OSGEO:41001") self.push_to_redis_zset(self.keyCategCoord, json.dumps(ordDic)) iso_code = rep['full_rep'].country.iso_code if rep['full_rep'].country.iso_code is not None else rep['full_rep'].registered_country.iso_code + country_name = rep['full_rep'].country.name if rep['full_rep'].country.name is not None else rep['full_rep'].registered_country.name self.push_to_redis_zset(self.keyCategCountry, iso_code) ordDic = OrderedDict() #keep fields with the same layout in redis ordDic['categ'] = categ @@ -130,10 +131,10 @@ class Geo_helper: "coord": coord, "categ": categ, "value": supposed_ip, - "country": rep['full_rep'].country.name, + "country": country_name, "specifName": rep['full_rep'].subdivisions.most_specific.name, "cityName": rep['full_rep'].city.name, - "regionCode": rep['full_rep'].country.iso_code, + "regionCode": iso_code, } j_to_send = json.dumps(to_send) self.serv_coord.publish(self.CHANNELDISP, j_to_send)