Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
Fix fallback mechanism for IP lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
coskundeniz committed Oct 12, 2023
1 parent ee9eb54 commit 13f4e8b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def get_location(
ip_address = proxy.split(":")[0]

if not ip_address:
logger.debug(f"Couldn't verify IP address for {proxy}!")
logger.info(f"Couldn't verify IP address for {proxy}!")
logger.info("Geolocation won't be set")
return (None, None)

Expand Down Expand Up @@ -160,6 +160,10 @@ def get_location(
response.json().get("latitude"),
response.json().get("longitude"),
)

if not (latitude and longitude):
raise Exception("Failed with https://ipapi.co")

break
except Exception as exp:
logger.debug(exp)
Expand All @@ -173,6 +177,10 @@ def get_location(
response.json().get("latitude"),
response.json().get("longitude"),
)

if not (latitude and longitude):
raise Exception("Failed with https://ifconfig.co/json")

break
except Exception as exp:
logger.debug(exp)
Expand All @@ -186,6 +194,10 @@ def get_location(
response.json()["latitude"],
response.json()["longitude"],
)

if not (latitude and longitude):
raise Exception("Failed with https://ipconfig.io/json")

break
except Exception as exp:
logger.debug(exp)
Expand All @@ -204,6 +216,7 @@ def get_location(

return (latitude, longitude)
else:
logger.error(f"Couldn't find latitude and longitude for {ip_address}!")
return (None, None)


Expand Down

0 comments on commit 13f4e8b

Please sign in to comment.