Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geoip conflicting with Python 3.5? #458

Closed
8BitAce opened this issue Jan 31, 2016 · 4 comments
Closed

Geoip conflicting with Python 3.5? #458

8BitAce opened this issue Jan 31, 2016 · 4 comments

Comments

@8BitAce
Copy link

8BitAce commented Jan 31, 2016

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?

@danielnaab
Copy link

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

@bogdal
Copy link
Contributor

bogdal commented Jan 31, 2016

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

@mociepka
Copy link
Contributor

mociepka commented Feb 1, 2016

I like python-geoip because it has separate package for data updates. I try fix it.
Ref. mitsuhiko/python-geoip#2

@mociepka
Copy link
Contributor

mociepka commented Feb 1, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants