From 349045e62c832af46fd669d92769ee28a3f045c8 Mon Sep 17 00:00:00 2001 From: Min RK Date: Tue, 31 Jul 2018 13:51:24 +0200 Subject: [PATCH] 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 --- jupyter_server/base/handlers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jupyter_server/base/handlers.py b/jupyter_server/base/handlers.py index d84c8be2b..0df951e70 100755 --- a/jupyter_server/base/handlers.py +++ b/jupyter_server/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 jupyter_server from jupyter_server._tz import utcnow @@ -419,6 +419,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: