From 65fef6274166678f59d6d81c9da68465a7c374bc Mon Sep 17 00:00:00 2001 From: Parker Date: Sun, 3 Nov 2024 23:05:03 -0600 Subject: [PATCH] Be certain data is present in the response --- app/util/log.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/util/log.py b/app/util/log.py index 46687c2..de60f23 100644 --- a/app/util/log.py +++ b/app/util/log.py @@ -32,7 +32,17 @@ def ip_to_location(ip): ) return "-, -", "-" - location = f'{data["country_name"]}, {data["city_name"]}' + location = "" + # Sometimes a certain name may not be present, so always check + if "city_name" in data: + location += data["city_name"] + + if "region_name" in data: + location += f', {data["region_name"]}' + + if "country_name" in data: + location += f', {data["country_name"]}' + isp = data["as"] return location, isp