Fix _geoip() format bug

This commit is contained in:
Igor Chubin 2021-01-21 23:12:06 +01:00
parent 49daae6f40
commit a6d0adbbf7

View file

@ -204,9 +204,12 @@ def _ipinfo(ip_addr):
def _geoip(ip_addr):
try:
_debug_log("[_geoip] %s search" % ip_addr)
response = GEOIP_READER.city(ip_addr)
city, region, country, ccode, lat, long = response.city.name, response.subdivisions.name, response.country.name, response.country.iso_code, response.location.latitude, response.location.longitude
except (geoip2.errors.AddressNotFoundError, AttributeError):
# print(response.subdivisions)
city, region, country, ccode, lat, long = response.city.name, response.subdivisions[0].names["en"], response.country.name, response.country.iso_code, response.location.latitude, response.location.longitude
_debug_log("[_geoip] %s found" % ip_addr)
except (geoip2.errors.AddressNotFoundError):
return None
return [city, region, country, ccode, lat, long]