fix: handle countries not recognized by geoip2 DB

The `geoip2` library returns `None` when it only identifies the continent
related to the IP address.
This commit is contained in:
Agrendalath
2024-01-24 18:44:25 +01:00
committed by Piotr Surowiec
parent 7037c8d27b
commit c1bd558ad6

View File

@@ -22,7 +22,7 @@ def country_code_from_ip(ip_addr: str) -> str:
try:
response = reader.country(ip_addr)
# pylint: disable=no-member
country_code = response.country.iso_code
country_code = response.country.iso_code or ""
except geoip2.errors.AddressNotFoundError:
country_code = ""
reader.close()