Merge pull request #3809 from minrk/ipaddress-unicode-py2

ip_address only accepts unicode on Python 2
Steven Silvester 8 years ago committed by GitHub
commit eed1caf32a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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,11 +427,15 @@ 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:
# 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

Loading…
Cancel
Save