Opened 5 years ago

Closed 5 years ago

#17059 closed Bug (fixed)

GeoIP returns no results for unicode input

Reported by: David Evans Owned by: nobody
Component: GIS Version: master
Severity: Normal Keywords:
Cc: d@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If you provide an IP address or hostname as a unicode string you will get no results, although the equivalent query with an str works fine.

>>> from django.contrib.gis import geoip
>>> g = geoip.GeoIP(path='/usr/share/GeoIP')
{'country_name': 'United States', 'country_code': 'US'}
{'country_name': None, 'country_code': None}
{'country_name': 'United States', 'country_code': 'US'}
{'country_name': None, 'country_code': None}

Given that Django supplies unicode strings everywhere (including in request.META['REMOTE_ADDR']) this may cause confusion and heartache.

Currently, the GeoiP._check_query() method checks that the input is an instance of basestring. This could be changed to require an instance of str or, preferably in my view, it could cast the input to an str (given that they're are only going to be IPs and hostnames anyway).

Change History (3)

comment:1 Changed 5 years ago by Aymeric Augustin

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Triage Stage: UnreviewedAccepted

comment:2 Changed 5 years ago by David Evans

Cc: d@… added

comment:3 Changed 5 years ago by jbronn

Resolution: fixed
Status: newclosed

In [17019]:

Fixed #17059 -- Encode GeoIP query strings properly so libGeoIP returns results for unicode strings.

Note: See TracTickets for help on using tickets.
Back to Top