#19168: GeoIP does not work properly under os X
------------------------------+------------------------------------
     Reporter:  tejinderss@…  |                    Owner:  nobody
         Type:  Bug           |                   Status:  reopened
    Component:  GIS           |                  Version:  1.4
     Severity:  Normal        |               Resolution:
     Keywords:                |             Triage Stage:  Accepted
    Has patch:  0             |      Needs documentation:  0
  Needs tests:  0             |  Patch needs improvement:  0
Easy pickings:  0             |                    UI/UX:  0
------------------------------+------------------------------------
Changes (by aaugustin):

 * stage:  Unreviewed => Accepted


Old description:

> django.contrib.gis.geoip.GeoIP does not read the city/country databases
> when called without any parameters. But when passing the city/country
> database files path explicitly to the init method, it works fine.
>
> Here is example:
> # Settings
> GEOIP_PATH                         = os.path.join(PROJECT_DIR, 'bin',
> 'GeoIP')
> GEOIP_COUNTRY                  = 'GeoIP.dat'
> GEOIP_CITY                          = 'GeoLiteCity.dat'
>
> In [1]: from django.contrib.gis.geoip import GeoIP
> In [2]: geo = GeoIP()
> In [3]: geo.info
> Out[3]: 'GeoIP Library:\n\t1.4.8\nCountry:\n\t\nCity:\n\t'
> In [4]: geo._city_file
> Out[4]:
> Path(u'/Users/tejindersingh/Projects/kyb/bin/GeoIP/GeoLiteCity.dat')
> In [5]: geo._country_file
> Out[5]: Path(u'/Users/tejindersingh/Projects/kyb/bin/GeoIP/GeoIP.dat')
> In [6]: geo.city('8.8.8.8')
> Invalid database type GeoIP Country Edition, expected GeoIP City Edition,
> Rev 1
>
> Doing same thing passing the path as parameters:
>
> In [7]: geo =
> GeoIP(city='/Users/tejindersingh/Projects/kyb/bin/GeoIP/GeoLiteCity.dat',
> country='/Users/tejindersingh/Projects/kyb/bin/GeoIP/GeoIP.dat')
> In [8]: geo.info
> Out[8]: 'GeoIP Library:\n\t1.4.8\nCountry:\n\tGEO-106FREE 20120207 Build
> 1 Copyright (c) 2011 MaxMind Inc All Rights Reserved\nCity:\n\tGEO-
> 533LITE 20121002 Build 1 Copyright (c) 2012 MaxMind Inc All Rights
> Reserved'
> In [9]: geo._city_file
> Out[9]: '/Users/tejindersingh/Projects/kyb/bin/GeoIP/GeoLiteCity.dat'
> In [10]: geo._country_file
> Out[10]: '/Users/tejindersingh/Projects/kyb/bin/GeoIP/GeoIP.dat'
> In [11]: geo.city('8.8.8.8')
> Out[11]:
> {'area_code': 650,
>  'charset': 0,
>  'city': u'Mountain View',
>  'continent_code': u'NA',
>  'country_code': u'US',
>  'country_code3': u'USA',
>  'country_name': u'United States',
>  'dma_code': 807,
>  'latitude': 37.4192008972168,
>  'longitude': -122.05740356445312,
>  'postal_code': u'94043',
>  'region': u'CA'}
>
> This happens under ox X mountain lion and with kyngchaos gis/gdal binary
> packages as well as self compile brews.

New description:

 django.contrib.gis.geoip.GeoIP does not read the city/country databases
 when called without any parameters. But when passing the city/country
 database files path explicitly to the init method, it works fine.

 Here is example:
 {{{
 # Settings
 GEOIP_PATH                         = os.path.join(PROJECT_DIR, 'bin',
 'GeoIP')
 GEOIP_COUNTRY                  = 'GeoIP.dat'
 GEOIP_CITY                          = 'GeoLiteCity.dat'
 }}}

 {{{
 In [1]: from django.contrib.gis.geoip import GeoIP
 In [2]: geo = GeoIP()
 In [3]: geo.info
 Out[3]: 'GeoIP Library:\n\t1.4.8\nCountry:\n\t\nCity:\n\t'
 In [4]: geo._city_file
 Out[4]:
 Path(u'/Users/tejindersingh/Projects/kyb/bin/GeoIP/GeoLiteCity.dat')
 In [5]: geo._country_file
 Out[5]: Path(u'/Users/tejindersingh/Projects/kyb/bin/GeoIP/GeoIP.dat')
 In [6]: geo.city('8.8.8.8')
 Invalid database type GeoIP Country Edition, expected GeoIP City Edition,
 Rev 1
 }}}

 Doing same thing passing the path as parameters:

 {{{
 In [7]: geo =
 GeoIP(city='/Users/tejindersingh/Projects/kyb/bin/GeoIP/GeoLiteCity.dat',
 country='/Users/tejindersingh/Projects/kyb/bin/GeoIP/GeoIP.dat')
 In [8]: geo.info
 Out[8]: 'GeoIP Library:\n\t1.4.8\nCountry:\n\tGEO-106FREE 20120207 Build 1
 Copyright (c) 2011 MaxMind Inc All Rights Reserved\nCity:\n\tGEO-533LITE
 20121002 Build 1 Copyright (c) 2012 MaxMind Inc All Rights Reserved'
 In [9]: geo._city_file
 Out[9]: '/Users/tejindersingh/Projects/kyb/bin/GeoIP/GeoLiteCity.dat'
 In [10]: geo._country_file
 Out[10]: '/Users/tejindersingh/Projects/kyb/bin/GeoIP/GeoIP.dat'
 In [11]: geo.city('8.8.8.8')
 Out[11]:
 {'area_code': 650,
  'charset': 0,
  'city': u'Mountain View',
  'continent_code': u'NA',
  'country_code': u'US',
  'country_code3': u'USA',
  'country_name': u'United States',
  'dma_code': 807,
  'latitude': 37.4192008972168,
  'longitude': -122.05740356445312,
  'postal_code': u'94043',
  'region': u'CA'}
 }}}

 This happens under ox X mountain lion and with kyngchaos gis/gdal binary
 packages as well as self compile brews.

--

Comment:

 Fixed formatting -- please use preview.

 If I understand correctly, the problem only occurs when `GEOIP_PATH` is a
 `unicode` rather than a `str`.

 The short answer is "make sure `settings.PROJECT_DIR` is a `str`". But in
 your case the path only contains ASCII characters so it shouldn't make any
 difference.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19168#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to