Work on IP2Location issues
This commit is contained in:
parent
0cd8c99216
commit
deef0c6443
@ -21,28 +21,24 @@ def log(link, ip, user_agent):
|
|||||||
.first()
|
.first()
|
||||||
)
|
)
|
||||||
|
|
||||||
if config.IP_TO_LOCATION:
|
if not config.IP_TO_LOCATION:
|
||||||
# Get IP to GEO via IP2Location.io
|
location = "-, -"
|
||||||
try:
|
isp = "-"
|
||||||
|
# Get IP to GEO via IPGeolocation.io
|
||||||
|
else:
|
||||||
url = f"https://api.ip2location.io/?key={config.API_KEY}&ip={ip}"
|
url = f"https://api.ip2location.io/?key={config.API_KEY}&ip={ip}"
|
||||||
data = requests.get(url).json()
|
data = requests.get(url).json()
|
||||||
|
print(data)
|
||||||
if "error" in data:
|
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:
|
|
||||||
config.LOG.error(
|
config.LOG.error(
|
||||||
"Error with IP2Location API. Likely wrong API key or"
|
"Error with IP2Location API. Likely wrong API key or"
|
||||||
" insufficient credits."
|
" insufficient funds."
|
||||||
)
|
)
|
||||||
location = "-, -"
|
location = "-, -"
|
||||||
isp = "-"
|
isp = "-"
|
||||||
else:
|
else:
|
||||||
location = "-, -"
|
location = f'{data["country_name"]}, {data["city"]}'
|
||||||
isp = "-"
|
isp = data["as"]
|
||||||
|
|
||||||
timestamp = datetime.datetime.now()
|
timestamp = datetime.datetime.now()
|
||||||
ua_string = user_agent_parser.Parse(user_agent)
|
ua_string = user_agent_parser.Parse(user_agent)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user