diff --git a/notebook/base/handlers.py b/notebook/base/handlers.py index e3fbddc2e0..582731639d 100755 --- a/notebook/base/handlers.py +++ b/notebook/base/handlers.py @@ -35,7 +35,7 @@ from traitlets.config import Application from ipython_genutils.path import filefind -from ipython_genutils.py3compat import string_types +from ipython_genutils.py3compat import string_types, PY3 import notebook from notebook._tz import utcnow @@ -427,11 +427,15 @@ def check_host(self): if host.startswith('[') and host.endswith(']'): host = host[1:-1] + if not PY3: + # ip_address only accepts unicode on Python 2 + host = host.decode('utf8', 'replace') + try: addr = ipaddress.ip_address(host) except ValueError: # Not an IP address: check against hostnames - allow = host in self.settings.get('local_hostnames', []) + allow = host in self.settings.get('local_hostnames', ['localhost']) else: allow = addr.is_loopback