Skip to content

Commit

Permalink
ip_address only accepts unicode on Python 2
Browse files Browse the repository at this point in the history
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
  • Loading branch information
minrk authored and Zsailer committed Sep 25, 2019
1 parent cd79a98 commit 349045e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion jupyter_server/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 jupyter_server
from jupyter_server._tz import utcnow
Expand Down Expand Up @@ -419,6 +419,10 @@ 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:
Expand Down

0 comments on commit 349045e

Please sign in to comment.