From ab51187a58ecf08ccdfe2bd7cb769314bcda9801 Mon Sep 17 00:00:00 2001 From: Agrendalath Date: Wed, 24 Jan 2024 18:44:25 +0100 Subject: [PATCH] fix: handle countries not recognized by geoip2 DB The `geoip2` library returns `None` when it only identifies the continent related to the IP address. --- openedx/core/djangoapps/geoinfo/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/geoinfo/api.py b/openedx/core/djangoapps/geoinfo/api.py index 9445b56fb998..76ca9f3f2fad 100644 --- a/openedx/core/djangoapps/geoinfo/api.py +++ b/openedx/core/djangoapps/geoinfo/api.py @@ -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()