Opened 13 years ago

Closed 13 years ago

#17059 closed Bug (fixed)

GeoIP returns no results for unicode input

Reported by: David Evans Owned by: nobody
Component: GIS Version: dev
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

Description

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')
>>> g.country('google.com')
{'country_name': 'United States', 'country_code': 'US'}
>>> g.country(u'google.com')
{'country_name': None, 'country_code': None}
>>> g.country('8.8.8.8')
{'country_name': 'United States', 'country_code': 'US'}
>>> g.country(u'8.8.8.8')
{'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 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedAccepted

comment:2 by David Evans, 13 years ago

Cc: d@… added

comment:3 by jbronn, 13 years ago

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