diff options
author | Parker <contact@pkrm.dev> | 2024-11-03 22:55:13 -0600 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-11-03 22:55:13 -0600 |
commit | deef0c644383d8e13eed64c0d84896c4ee4ef867 (patch) | |
tree | 19da9648b548cd9f2101d40f865831d934f0f35c /app/util/log.py | |
parent | 0cd8c992161127b190e5ea0af8198e35517821dc (diff) |
Work on IP2Location issues
Diffstat (limited to 'app/util/log.py')
-rw-r--r-- | app/util/log.py | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/app/util/log.py b/app/util/log.py index f25641a..ac7d99e 100644 --- a/app/util/log.py +++ b/app/util/log.py @@ -21,28 +21,24 @@ def log(link, ip, user_agent): .first() ) - if config.IP_TO_LOCATION: - # Get IP to GEO via IP2Location.io - try: - url = f"https://api.ip2location.io/?key={config.API_KEY}&ip={ip}" - data = requests.get(url).json() - if "error" in data: - raise Exception("Error") - else: - location = f'{data["country_name"]}, {data["city"]}' - isp = data["as"] - - # Fatal error, maybe API is down? - except: + if not config.IP_TO_LOCATION: + location = "-, -" + isp = "-" + # Get IP to GEO via IPGeolocation.io + else: + url = f"https://api.ip2location.io/?key={config.API_KEY}&ip={ip}" + data = requests.get(url).json() + print(data) + if "error" in data: config.LOG.error( "Error with IP2Location API. Likely wrong API key or" - " insufficient credits." + " insufficient funds." ) location = "-, -" isp = "-" - else: - location = "-, -" - isp = "-" + else: + location = f'{data["country_name"]}, {data["city"]}' + isp = data["as"] timestamp = datetime.datetime.now() ua_string = user_agent_parser.Parse(user_agent) |