Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ip_address only accepts unicode on Python 2 #3809

Merged
merged 2 commits into from
Aug 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additionally, added 'localhost' as the default here so that it is defined by default when used outside NotebookApp, e.g. nbdime.

else:
allow = addr.is_loopback

Expand Down