Skip to content

Commit eed1caf

Browse files
authored
Merge pull request #3809 from minrk/ipaddress-unicode-py2
ip_address only accepts unicode on Python 2
2 parents b94cc44 + e33a16f commit eed1caf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

notebook/base/handlers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
from traitlets.config import Application
3737
from ipython_genutils.path import filefind
38-
from ipython_genutils.py3compat import string_types
38+
from ipython_genutils.py3compat import string_types, PY3
3939

4040
import notebook
4141
from notebook._tz import utcnow
@@ -427,11 +427,15 @@ def check_host(self):
427427
if host.startswith('[') and host.endswith(']'):
428428
host = host[1:-1]
429429

430+
if not PY3:
431+
# ip_address only accepts unicode on Python 2
432+
host = host.decode('utf8', 'replace')
433+
430434
try:
431435
addr = ipaddress.ip_address(host)
432436
except ValueError:
433437
# Not an IP address: check against hostnames
434-
allow = host in self.settings.get('local_hostnames', [])
438+
allow = host in self.settings.get('local_hostnames', ['localhost'])
435439
else:
436440
allow = addr.is_loopback
437441

0 commit comments

Comments
 (0)