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
This commit is contained in:
Min RK 2018-07-31 13:51:24 +02:00
parent ceaf1c1158
commit 1901eeac63

View File

@ -35,7 +35,7 @@ from notebook._sysinfo import get_sys_info
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 @@ class IPythonHandler(AuthenticatedHandler):
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: