Skip to content

Commit c8254c9

Browse files
authored
Merge pull request #2728 from rtfd/fix-ip-404
Fix 404 being raised on invalid IP.
2 parents ba644dd + 8277569 commit c8254c9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

readthedocs/donate/signals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
if PROMO_GEO_PATH:
1414
import geoip2.database # noqa
15+
from geoip2.errors import AddressNotFoundError # noqa
1516
geo_reader = geoip2.database.Reader(PROMO_GEO_PATH)
1617

1718

@@ -171,7 +172,7 @@ def attach_promo_data(sender, **kwargs):
171172
try:
172173
geo_response = geo_reader.city(ip)
173174
country_code = geo_response.country.iso_code
174-
except ValueError: # Invalid IP
175+
except (AddressNotFoundError, ValueError): # Invalid IP
175176
country_code = None
176177

177178
# Try to get a promo if we should be using one.

0 commit comments

Comments
 (0)