Fix #3391 -- Don't crash on GeoIP lookup failure

This commit is contained in:
Raphael Michel
2023-06-06 17:12:17 +02:00
parent 0b4064f14f
commit 50ff968c17
2 changed files with 12 additions and 4 deletions

View File

@@ -25,6 +25,7 @@ import time
from django.conf import settings
from django.contrib.gis.geoip2 import GeoIP2
from django.core.cache import cache
from geoip2.errors import AddressNotFoundError
from pretix.helpers.http import get_client_ip
@@ -50,7 +51,10 @@ def _get_country(request):
if not _geoip:
_geoip = GeoIP2()
res = _geoip.country(get_client_ip(request))
try:
res = _geoip.country(get_client_ip(request))
except AddressNotFoundError:
return None
return res['country_code']