Saleor: Geoip conflicting with Python 3.5?

Created on 31 Jan 2016  路  4Comments  路  Source: mirumee/saleor

It appears that python-geoip won't work with the current setup (utilizing Python 3.5).
I get this stack trace:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 1.9.1
Python Version: 3.5.1
Installed Applications:
['offsite_storage',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.sitemaps',
 'django.contrib.sites',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.auth',
 'saleor.userprofile',
 'saleor.product',
 'saleor.cart',
 'saleor.checkout',
 'saleor.core',
 'saleor.order',
 'saleor.registration',
 'saleor.dashboard',
 'saleor.shipping',
 'versatileimagefield',
 'babeldjango',
 'bootstrap3',
 'django_prices',
 'emailit',
 'mptt',
 'payments',
 'selectable',
 'materializecssform',
 'rest_framework']
Installed Middleware:
['django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'babeldjango.middleware.LocaleMiddleware',
 'saleor.cart.middleware.CartMiddleware',
 'saleor.core.middleware.DiscountMiddleware',
 'saleor.core.middleware.GoogleAnalytics',
 'saleor.core.middleware.CountryMiddleware',
 'saleor.core.middleware.CurrencyMiddleware']



Traceback:

File "/home/eightbit/saleor/env/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
  123.                 response = middleware_method(request)

File "/home/eightbit/saleor/saleor/saleor/core/middleware.py" in process_request
  37.             request.country = get_country_by_ip(request.META['REMOTE_ADDR'])

File "/home/eightbit/saleor/saleor/saleor/core/__init__.py" in get_country_by_ip
  14.     geo_data = geolite2.lookup(ip_address)

File "/home/eightbit/saleor/env/lib/python3.5/site-packages/geoip.py" in lookup
  364.         return self._get_actual_db().lookup(ip_addr)

File "/home/eightbit/saleor/env/lib/python3.5/site-packages/geoip.py" in _get_actual_db
  350.             rv = self._load_database()

File "/home/eightbit/saleor/env/lib/python3.5/site-packages/geoip.py" in _load_database
  342.         return mod.loader(self, sys.modules[__name__])

File "/home/eightbit/saleor/env/lib/python3.5/site-packages/_geoip_geolite2/__init__.py" in loader
  9.     return mod.open_database(filename)

File "/home/eightbit/saleor/env/lib/python3.5/site-packages/geoip.py" in open_database
  508.     md = _read_mmdb_metadata(buf)

File "/home/eightbit/saleor/env/lib/python3.5/site-packages/geoip.py" in _read_mmdb_metadata
  382.                        buf.size() - MMDB_METADATA_BLOCK_MAX_SIZE)

Exception Type: TypeError at /
Exception Value: a bytes-like object is required, not 'str'

python-geoip seems to be abandoned from looking at its GitHub page. Perhaps it should be replaced with something else?

Most helpful comment

maxminddb-geolite2 has the same approach but it is maintained. I replaced python-geoip by it.

All 4 comments

I merged that commit and had the same problem, also (with Python 3.5).

@mociepka I would recommend maxminddb-geolite2 which supports Python 3.

I like python-geoip because it has separate package for data updates. I try fix it.
Ref. https://github.com/mitsuhiko/python-geoip/issues/2

maxminddb-geolite2 has the same approach but it is maintained. I replaced python-geoip by it.

Was this page helpful?
0 / 5 - 0 ratings