GeoIPError at / Invalid database type; record_* methods expect City database
tpaz opened this issue · 10 comments
have done nothing but upgraded from 0.2.2 to 0.2.3 and got this Django crash.
What's wrong?
Request Method: GET
Request URL: http://staging.thesolitaires.com/
Django Version: 1.3.1
Exception Type: GeoIPError
Exception Value:
Invalid database type; record_* methods expect City database
Exception Location: /home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/pygeoip-0.2.3-py2.6.egg/pygeoip/init.py in record_by_addr, line 543
Python Executable: /usr/bin/python
Python Version: 2.6.5
Python Path:
['/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/Django-1.3.1-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/gameportal-0.9.1.1_806_g1842eac-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/wsclient-0.9.1.1_806_g1842eac-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/kgputils-0.9.1.1_806_g1842eac-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/django_profiles-0.2-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/django_simple_captcha-0.3.1-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/django_cms-2.1.2-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/djangorestframework-0.3.3-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/South-0.7.4-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/oauth2-1.5.211-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/python_openid-2.2.5-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/pycrypto-2.3-py2.6-linux-i686.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/zope.interface-3.8.0-py2.6-linux-i686.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/pygeoip-0.2.3-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/psycopg2-2.4.5-py2.6-linux-i686.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/iso8601-0.1.4-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/lxml-2.3.4-py2.6-linux-i686.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/ConcurrentLogHandler-0.8.4-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/httplib2-0.7.4-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/Twisted-12.0.0-py2.6-linux-i686.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/pyOpenSSL-0.12-py2.6-linux-i686.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/pyserial-2.6-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/thrift-0.8.0-py2.6-linux-i686.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/IPy-0.75-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/stomper-0.2.4-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/simplejson-2.5.0-py2.6-linux-i686.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/telephus-0.7.1-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/django_registration-0.8_alpha_1-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/django_socialregistration-0.4.5-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/facebook_python_sdk-0.1.1-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/python_daemon-1.6-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/python_memcached-1.48-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/gunicorn-0.14.2-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/Pillow-1.7.7-py2.6-linux-i686.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/recipes-0.9.1.1_806_g1842eac-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/zc.recipe.egg-1.3.2-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/zc.buildout-1.5.2-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/lockfile-0.9.1-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/setuptools-0.6c11-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/six-1.1.0-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/URLObject-2.0.1-py2.6.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/PIL-1.1.7-py2.6-linux-i686.egg',
'/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/django_classy_tags-0.3.4.1-py2.6.egg',
'/usr/lib/python26.zip',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/lib/python2.6/site-packages']
Server time: Thu, 12 Apr 2012 10:57:34 +0000
all trace below:
Environment:
Request Method: GET
Request URL: http://staging.thesolitaires.com/
Django Version: 1.3.1
Python Version: 2.6.5
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admindocs',
'django.contrib.admin',
'django.contrib.humanize',
'django.contrib.sitemaps',
'cms',
'cms.plugins.text',
'cms.plugins.picture',
'cms.plugins.link',
'cms.plugins.file',
'cms.plugins.snippet',
'mptt',
'publisher',
'menus',
'registration',
'profiles',
'captcha',
'socialregistration',
'south',
'djangorestframework',
'gunicorn',
'gameportal.portal',
'gameportal.players',
'gameportal.fbapp',
'gameportal.chat',
'gameportal.money',
'gameportal.eyecon',
'gameportal.aquapay',
'gameportal.sessiontracking',
'gameportal.geoip',
'gameportal.solver',
'gameportal.cron',
'gameportal.maintenance',
'gameportal.articles',
'gameportal.userprofile',
'gameportal.cashier',
'gameportal.blacklist',
'gameportal.default_avatars',
'gameportal.contactus',
'gameportal.g2s',
'gameportal.notifications']
Installed Middleware:
('gameportal.geoip.IPCheckMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'djangoext.log.LoggingMiddleware',
'socialregistration.middleware.FacebookMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.media.PlaceholderMediaMiddleware',
'gameportal.maintenance.middleware.MaintenanceModeMiddleware',
'gameportal.players.middleware.PlayerMiddleware',
'gameportal.sessiontracking.middleware.SessionTrackingMiddleware')
Traceback:
File "/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/Django-1.3.1-py2.6.egg/django/core/handlers/base.py" in get_response
-
File "/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/gameportal-0.9.1.1_806_g1842eac-py2.6.egg/gameportal/geoip/middleware.py" in process_request
response = middleware_method(request)
-
File "/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/kgputils-0.9.1.1_806_g1842eac-py2.6.egg/memoize.py" in wrap
if not is_allowed(request.META['REMOTE_ADDR']):
-
File "/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/gameportal-0.9.1.1_806_g1842eac-py2.6.egg/gameportal/geoip/models.py" in is_allowed
_cache[args] = ret = fn(*args)
-
File "/home/kgp/kgp-0.9.1.1-806-g1842eac/eggs/pygeoip-0.2.3-py2.6.egg/pygeoip/init.py" in record_by_addr
gdata = get_geo_data(addr)
-
raise GeoIPError('Invalid database type; record_\* methods expect City database')
Exception Type: GeoIPError at /
Exception Value: Invalid database type; record_* methods expect City database
You are using a City database, right?
yes, probably :)
On Fri, Apr 13, 2012 at 6:59 PM, Jennifer Ennis <
reply@reply.github.com
wrote:
You are using a City database, right?
Reply to this email directly or view it on GitHub:
#7 (comment)
Rgrds
Tomer
Well I am not able to duplicate this error, so you are probably not using a City database. Methods that start with record_ can't be used on anything but a City database.
am using this: GeoLiteCity.dat
switched back to 0.2.2, solved my crash problem.
On Fri, Apr 13, 2012 at 7:13 PM, Jennifer Ennis <
reply@reply.github.com
wrote:
Well I am not able to duplicate this error, so you are probably not using
a City database. Methods that start with record_ can't be used on anything
but a City database.
Reply to this email directly or view it on GitHub:
#7 (comment)
Rgrds
Tomer
I just tested with the latest GeoLiteCity.dat and no issues for me. I'll leave this ticket open for a bit and see if anyone else has this problem, because I can't do anything about it if I can't reproduce it.
with which Cache have you tested? we are using MMAP_CACHE
I saw few corrections other contributors added like "Add support for
non-gzipped .dat files when in MEMORY_CACHE
mode.b3a80ec
"
though it isn't the cache we use, maybe it shall solve the bug...(?)
On Fri, Apr 13, 2012 at 7:27 PM, Jennifer Ennis <
reply@reply.github.com
wrote:
I just tested with the latest GeoLiteCity.dat and no issues for me. I'll
leave this ticket open for a bit and see if anyone else has this problem,
because I can't do anything about it if I can't reproduce it.
Reply to this email directly or view it on GitHub:
#7 (comment)
Rgrds
Tomer
I can confirm this issue with pygeoip 0.2.3 using MMAP_CACHE. Switching to STANDARD does not result in the error, and rolling back to pygeoip 0.2.2 also fixes the problem.
All of my testing used the latest (as of this posting) GeoLiteCity.dat, downloaded from here:
http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
>>> import pygeoip
>>> from django.conf import settings
>>> settings.GEOIP_DATA_FILE
'/home/derek/dev/townsquare/data/GeoLiteCity.dat'
>>> geoip = pygeoip.GeoIP(settings.GEOIP_DATA_FILE, pygeoip.MMAP_CACHE)
>>> geoip.record_by_addr('68.111.196.32')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/derek/.virtualenvs/townsquare/lib/python2.7/site-packages/pygeoip/__init__.py", line 543, in record_by_addr
raise GeoIPError('Invalid database type; record_* methods expect City database')
GeoIPError: Invalid database type; record_* methods expect City database
>>> geoip._databaseType
1
It appears that geo._databaseType
has an incorrect value; it looks like it should be set to 6 or 2 (CITY_EDITION_REV0
and CITY_EDITION_REV1
, respectively)
Mea culpa. My pull request that was merged recently is the cause of this problem. I'll send another one this week which fixes this bug.
Thank you guys
On Apr 17, 2012 12:04 AM, "Christian Hudon" <
reply@reply.github.com>
wrote:
Mea culpa. My pull request that was merged recently is the cause of this
problem. I'll send another one this week which fixes this bug.
Reply to this email directly or view it on GitHub:
#7 (comment)
With pygeoip 0.2.3 using anything other than STANDARD I get the following errors:
>>> gi = pygeoip.GeoIP("/home/angel/temp/GeoLiteCity.dat", pygeoip.MEMORY_CACHE)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/angel/.virtualenvs/venv/local/lib/python2.7/site-packages/pygeoip/__init__.py", line 101, i
n __init__
self._memoryBuffer = self._filehandle.read()
File "/usr/lib/python2.7/gzip.py", line 245, in read
self._read(readsize)
File "/usr/lib/python2.7/gzip.py", line 287, in _read
self._read_gzip_header()
File "/usr/lib/python2.7/gzip.py", line 181, in _read_gzip_header
raise IOError, 'Not a gzipped file'
IOError: Not a gzipped file
>>> gi = pygeoip.GeoIP("/home/angel/temp/GeoLiteCity.dat", pygeoip.MMAP_CACHE)
/home/angel/.virtualenvs/venv/local/lib/python2.7/site-packages/pygeoip/__init__.py:122: UnicodeWarning:
Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if delim == six.u(chr(255) * 3):
>>> gi.record_by_addr("149.48.228.139")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/angel/.virtualenvs/venv/local/lib/python2.7/site-packages/pygeoip/__init__.py", line 543, in record_by_addr
raise GeoIPError('Invalid database type; record_* methods expect City database')
pygeoip.GeoIPError: Invalid database type; record_* methods expect City database
>>> gi = pygeoip.GeoIP("/home/angel/temp/GeoLiteCity.dat", pygeoip.STANDARD)
>>> gi.record_by_addr("149.48.228.139")
{'city': u'Arlington', 'region_name': u'VA', 'area_code': 703, 'time_zone': 'America/New_York', 'longitude': -77.0533, 'metro_code': 'Washington, DC', 'country_code3': 'USA', 'latitude': 38.860000000000014, 'postal_code': u'22202', 'dma_code': 511, 'country_code': 'US', 'country_name': 'United States'}
Reverting to 0.2.2 seems to solve the issue for now.