Opened 11 years ago

Closed 11 years ago

#19168 closed Bug (duplicate)

GeoIP does not work properly under os X

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

Description (last modified by Aymeric Augustin)

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.

Change History (6)

comment:1 by tejinderss@…, 11 years ago

Resolution: invalid
Status: newclosed

comment:2 by tejinderss@…, 11 years ago

Resolution: invalid
Status: closedreopened

comment:3 by anonymous, 11 years ago

If I add str to the GEOIP_PATH like this in settings:

GEOIP_PATH = str(os.path.join(PROJECT_DIR, 'bin', 'GeoIP'))

then it works fine. I am using:

from unipath import FSPath as Path

to manage paths.

Same setup works fine under ubuntu linux without any change.

comment:4 by Aymeric Augustin, 11 years ago

Description: modified (diff)
Triage Stage: UnreviewedAccepted

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.

comment:5 by Aymeric Augustin, 11 years ago

Status: reopenednew

comment:6 by Claude Paroz, 11 years ago

Resolution: duplicate
Status: newclosed

Fixed in #20384

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