Skip to content

Commit

Permalink
Merge pull request #3809 from minrk/ipaddress-unicode-py2
Browse files Browse the repository at this point in the history
ip_address only accepts unicode on Python 2
  • Loading branch information
blink1073 authored Aug 13, 2018
2 parents b94cc44 + e33a16f commit eed1caf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions notebook/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -427,11 +427,15 @@ 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:
# 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

Expand Down

0 comments on commit eed1caf

Please sign in to comment.