Search code examples
pythondjangogeolocation

Django GeoIP Error; invalid path type


After struggling to get GeoIp installed properly for a Django project, I finally appear to have installed it properly via universal geoip with brew.

Unfortunately, when trying it out in the shell, I'm receiving the following error:

>>> from django.contrib.gis.utils.geoip import GeoIP
>>> g = GeoIP()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/gis/utils/geoip.py", line 193, in __init__
raise TypeError('Invalid path type: %s' % type(path).__name__)

TypeError: Invalid path type: tuple

I've been trying to properly install GeoIP for about seven hours so any insight into this latest error would be very much appreciated.


Solution

  • If you really have a comma in there, then you are setting GEOIP_PATH to a tuple and not a string, which would explain the error. If this is the case, simply remove the comma:

    # settings.py
    
    import os
    
    BASE_DIR = os.path.abspath(os.path.dirname(__file__))
    GEOIP_PATH = os.path.join(BASE_DIR, 'geoip')