Opened 17 months ago

Closed 17 months ago

Last modified 17 months ago

#21996 closed Bug (fixed)

UnicodeDecodeError when calling GeoIP.country

Reported by: Florent Messa <florent.messa@…> Owned by: claudep
Component: GIS Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

GeoIP.country('IP') raises an UnicodeDecodeError when dealing with countries with accents.

For example:

g = GeoIP()
g.country('200.7.49.81')

Should returns "Curaçao" instead:

In [2]: g = GeoIP()

In [3]: g.country('200.7.49.81')
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-3-3f21b2954917> in <module>()
----> 1 g.country('200.7.49.81')

/Users/thoas/Sites/Python/Ulule/.ven/ulule/lib/python2.7/site-packages/django/contrib/gis/geoip/base.pyc in country(self, query)
    193         # Returning the country code and name
    194         return {'country_code' : self.country_code(query),
--> 195                 'country_name' : self.country_name(query),
    196                 }
    197

/Users/thoas/Sites/Python/Ulule/.ven/ulule/lib/python2.7/site-packages/django/contrib/gis/geoip/base.pyc in country_name(self, query)
    179         if self._country:
    180             if ipv4_re.match(query):
--> 181                 return GeoIP_country_name_by_addr(self._country, enc_query)
    182             else:
    183                 return GeoIP_country_name_by_name(self._country, enc_query)

/Users/thoas/Sites/Python/Ulule/.ven/ulule/lib/python2.7/site-packages/django/contrib/gis/geoip/prototypes.pyc in _err_check(result, func, cargs)
    103     def _err_check(result, func, cargs):
    104         if result:
--> 105             return result.decode()
    106         return result
    107     func.restype = c_char_p

Attachments (1)

21996.diff (1.5 KB) - added by claudep 17 months ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 17 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to claudep
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

Changed 17 months ago by claudep

comment:2 Changed 17 months ago by claudep

  • Has patch set

Could you please test the attached patch?

comment:3 Changed 17 months ago by Florent Messa <florent.messa@…>

Good for me, thank you for your quick review.

comment:4 Changed 17 months ago by Claude Paroz <claude@…>

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

In fb1e3435a4d7e0265f19a1a9f130c9485fb8dfe9:

Fixed #21996 -- Used proper encoding for GeoIP content

Thanks Florent Messa for the report.

comment:5 Changed 17 months ago by Claude Paroz <claude@…>

In 76700c5437d4b5187f58a3f99104f45002d1524e:

[1.6.x] Fixed #21996 -- Used proper encoding for GeoIP content

Thanks Florent Messa for the report.
Backport of fb1e3435a4 from master.

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