Code

Opened 3 years ago

Closed 2 years ago

#17059 closed Bug (fixed)

GeoIP returns no results for unicode input

Reported by: drhevans 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

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).

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 3 years ago by drhevans

  • Cc d@… added

comment:3 Changed 2 years ago by jbronn

  • Resolution set to fixed
  • Status changed from new to closed

In [17019]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.