Code

#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 aaugustin)

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.

Attachments (0)

Change History (6)

comment:1 Changed 18 months ago by tejinderss@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

comment:2 Changed 18 months ago by tejinderss@…

  • Resolution invalid deleted
  • Status changed from closed to reopened

comment:3 Changed 18 months ago by anonymous

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 Changed 17 months ago by aaugustin

  • Description modified (diff)
  • Triage Stage changed from Unreviewed to Accepted

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 Changed 13 months ago by aaugustin

  • Status changed from reopened to new

comment:6 Changed 11 months ago by claudep

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

Fixed in #20384

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.