We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Geoip conflicting with Python 3.5?
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?


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `saleor/core/__init__.py`
Content:
```
1 from __future__ import unicode_literals
2 
3 from babel.numbers import get_territory_currencies
4 from django.conf import settings
5 from django_countries import countries
6 from django_countries.fields import Country
7 from geoip import geolite2
8 
9 TOKEN_PATTERN = ('(?P<token>[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}'
10                  '-[0-9a-z]{12})')
11 
12 
13 def get_country_by_ip(ip_address):
14     geo_data = geolite2.lookup(ip_address)
15     if geo_data and geo_data.country in countries:
16         return Country(geo_data.country)
17 
18 
19 def get_currency_for_country(country):
20     currencies = get_territory_currencies(country.code)
21     if len(currencies):
22         main_currency = currencies[0]
23         if main_currency in settings.AVAILABLE_CURRENCIES:
24             return main_currency
25     return settings.DEFAULT_CURRENCY
26
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/saleor/core/__init__.py b/saleor/core/__init__.py
--- a/saleor/core/__init__.py
+++ b/saleor/core/__init__.py
@@ -4,16 +4,20 @@
 from django.conf import settings
 from django_countries import countries
 from django_countries.fields import Country
-from geoip import geolite2
+from geolite2 import geolite2
 
 TOKEN_PATTERN = ('(?P<token>[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}'
                  '-[0-9a-z]{12})')
 
 
 def get_country_by_ip(ip_address):
-    geo_data = geolite2.lookup(ip_address)
-    if geo_data and geo_data.country in countries:
-        return Country(geo_data.country)
+    reader = geolite2.reader()
+    geo_data = reader.get(ip_address)
+    geolite2.close()
+    if geo_data and 'country' in geo_data and 'iso_code' in geo_data['country']:
+        country_iso_code = geo_data['country']['iso_code']
+        if country_iso_code in countries:
+            return Country(country_iso_code)
 
 
 def get_currency_for_country(country):

{"golden_diff": "diff --git a/saleor/core/__init__.py b/saleor/core/__init__.py\n--- a/saleor/core/__init__.py\n+++ b/saleor/core/__init__.py\n@@ -4,16 +4,20 @@\n from django.conf import settings\n from django_countries import countries\n from django_countries.fields import Country\n-from geoip import geolite2\n+from geolite2 import geolite2\n \n TOKEN_PATTERN = ('(?P<token>[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}'\n                  '-[0-9a-z]{12})')\n \n \n def get_country_by_ip(ip_address):\n-    geo_data = geolite2.lookup(ip_address)\n-    if geo_data and geo_data.country in countries:\n-        return Country(geo_data.country)\n+    reader = geolite2.reader()\n+    geo_data = reader.get(ip_address)\n+    geolite2.close()\n+    if geo_data and 'country' in geo_data and 'iso_code' in geo_data['country']:\n+        country_iso_code = geo_data['country']['iso_code']\n+        if country_iso_code in countries:\n+            return Country(country_iso_code)\n \n \n def get_currency_for_country(country):\n", "issue": "Geoip conflicting with Python 3.5?\nIt appears that python-geoip won't work with the current setup (utilizing Python 3.5).\nI get this stack trace:\n\n```\nEnvironment:\n\nRequest Method: GET\nRequest URL: http://127.0.0.1:8000/\n\nDjango Version: 1.9.1\nPython Version: 3.5.1\nInstalled Applications:\n['offsite_storage',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.messages',\n 'django.contrib.sitemaps',\n 'django.contrib.sites',\n 'django.contrib.staticfiles',\n 'django.contrib.admin',\n 'django.contrib.auth',\n 'saleor.userprofile',\n 'saleor.product',\n 'saleor.cart',\n 'saleor.checkout',\n 'saleor.core',\n 'saleor.order',\n 'saleor.registration',\n 'saleor.dashboard',\n 'saleor.shipping',\n 'versatileimagefield',\n 'babeldjango',\n 'bootstrap3',\n 'django_prices',\n 'emailit',\n 'mptt',\n 'payments',\n 'selectable',\n 'materializecssform',\n 'rest_framework']\nInstalled Middleware:\n['django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.common.CommonMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n 'django.middleware.locale.LocaleMiddleware',\n 'babeldjango.middleware.LocaleMiddleware',\n 'saleor.cart.middleware.CartMiddleware',\n 'saleor.core.middleware.DiscountMiddleware',\n 'saleor.core.middleware.GoogleAnalytics',\n 'saleor.core.middleware.CountryMiddleware',\n 'saleor.core.middleware.CurrencyMiddleware']\n\n\n\nTraceback:\n\nFile \"/home/eightbit/saleor/env/lib/python3.5/site-packages/django/core/handlers/base.py\" in get_response\n  123.                 response = middleware_method(request)\n\nFile \"/home/eightbit/saleor/saleor/saleor/core/middleware.py\" in process_request\n  37.             request.country = get_country_by_ip(request.META['REMOTE_ADDR'])\n\nFile \"/home/eightbit/saleor/saleor/saleor/core/__init__.py\" in get_country_by_ip\n  14.     geo_data = geolite2.lookup(ip_address)\n\nFile \"/home/eightbit/saleor/env/lib/python3.5/site-packages/geoip.py\" in lookup\n  364.         return self._get_actual_db().lookup(ip_addr)\n\nFile \"/home/eightbit/saleor/env/lib/python3.5/site-packages/geoip.py\" in _get_actual_db\n  350.             rv = self._load_database()\n\nFile \"/home/eightbit/saleor/env/lib/python3.5/site-packages/geoip.py\" in _load_database\n  342.         return mod.loader(self, sys.modules[__name__])\n\nFile \"/home/eightbit/saleor/env/lib/python3.5/site-packages/_geoip_geolite2/__init__.py\" in loader\n  9.     return mod.open_database(filename)\n\nFile \"/home/eightbit/saleor/env/lib/python3.5/site-packages/geoip.py\" in open_database\n  508.     md = _read_mmdb_metadata(buf)\n\nFile \"/home/eightbit/saleor/env/lib/python3.5/site-packages/geoip.py\" in _read_mmdb_metadata\n  382.                        buf.size() - MMDB_METADATA_BLOCK_MAX_SIZE)\n\nException Type: TypeError at /\nException Value: a bytes-like object is required, not 'str'\n```\n\npython-geoip seems to be abandoned from looking at its GitHub page. Perhaps it should be replaced with something else?\n\n", "before_files": [{"content": "from __future__ import unicode_literals\n\nfrom babel.numbers import get_territory_currencies\nfrom django.conf import settings\nfrom django_countries import countries\nfrom django_countries.fields import Country\nfrom geoip import geolite2\n\nTOKEN_PATTERN = ('(?P<token>[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}'\n                 '-[0-9a-z]{12})')\n\n\ndef get_country_by_ip(ip_address):\n    geo_data = geolite2.lookup(ip_address)\n    if geo_data and geo_data.country in countries:\n        return Country(geo_data.country)\n\n\ndef get_currency_for_country(country):\n    currencies = get_territory_currencies(country.code)\n    if len(currencies):\n        main_currency = currencies[0]\n        if main_currency in settings.AVAILABLE_CURRENCIES:\n            return main_currency\n    return settings.DEFAULT_CURRENCY\n", "path": "saleor/core/__init__.py"}], "after_files": [{"content": "from __future__ import unicode_literals\n\nfrom babel.numbers import get_territory_currencies\nfrom django.conf import settings\nfrom django_countries import countries\nfrom django_countries.fields import Country\nfrom geolite2 import geolite2\n\nTOKEN_PATTERN = ('(?P<token>[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}'\n                 '-[0-9a-z]{12})')\n\n\ndef get_country_by_ip(ip_address):\n    reader = geolite2.reader()\n    geo_data = reader.get(ip_address)\n    geolite2.close()\n    if geo_data and 'country' in geo_data and 'iso_code' in geo_data['country']:\n        country_iso_code = geo_data['country']['iso_code']\n        if country_iso_code in countries:\n            return Country(country_iso_code)\n\n\ndef get_currency_for_country(country):\n    currencies = get_territory_currencies(country.code)\n    if len(currencies):\n        main_currency = currencies[0]\n        if main_currency in settings.AVAILABLE_CURRENCIES:\n            return main_currency\n    return settings.DEFAULT_CURRENCY\n", "path": "saleor/core/__init__.py"}]}