Skip to content

Commit

Permalink
Handle urlparse ValueError on invalid IP addresses in python >= 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
dbnicholson committed Jun 15, 2023
1 parent 3a9bb05 commit a516347
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions kolibri/core/discovery/utils/network/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re

from six import raise_from
from six.moves.urllib.parse import urlparse

from . import errors
Expand Down Expand Up @@ -117,8 +118,12 @@ def parse_address_into_components(address): # noqa C901
if "://" not in address:
address = "http://" + address

# parse out the URL into its components
parsed = urlparse(address)
# parse out the URL into its components. On python >= 3.11, this
# will throw a ValueError on invalid IP addresses.
try:
parsed = urlparse(address)
except ValueError as e:
raise_from(errors.InvalidHostname(address), e)
p_scheme = parsed.scheme
p_hostname = parsed.hostname
p_path = parsed.path.rstrip("/") + "/"
Expand Down

0 comments on commit a516347

Please sign in to comment.