From 1901eeac63866e41d6cda9e60ea5a778020e3b3b Mon Sep 17 00:00:00 2001 From: Min RK Date: Tue, 31 Jul 2018 13:51:24 +0200 Subject: [PATCH 1/2] ip_address only accepts unicode on Python 2 ipaddress.ip_address('127.0.0.1') fails with ValueError on Python 2 need to decode it, otherwise 127.0.0.1 won't be treated as local --- notebook/base/handlers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/notebook/base/handlers.py b/notebook/base/handlers.py index e3fbddc2e0..278b3b428f 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,6 +427,10 @@ 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: From e33a16f42f7c864ac97cd0d010ac37ba6fc7be22 Mon Sep 17 00:00:00 2001 From: Min RK Date: Tue, 31 Jul 2018 14:02:12 +0200 Subject: [PATCH 2/2] use localhost as default local hostname so this list isn't empty when these handlers are used outside NotebookApp --- notebook/base/handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebook/base/handlers.py b/notebook/base/handlers.py index 278b3b428f..582731639d 100755 --- a/notebook/base/handlers.py +++ b/notebook/base/handlers.py @@ -435,7 +435,7 @@ def check_host(self): 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