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:
committed by
Piotr Surowiec
parent
7037c8d27b
commit
c1bd558ad6
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user