diff options
author | Matt Eaton <agnosticdev@gmail.com> | 2018-03-20 06:41:37 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2018-03-20 06:41:37 (GMT) |
commit | 2cb4661707818cfd92556e7fdf9068a993577002 (patch) | |
tree | 0c3f6933e3e5117b5289845d998da35da46f8d72 /Lib/urllib/parse.py | |
parent | 7389fd935c95b4b6f094312294e703ee0de18719 (diff) | |
download | cpython-2cb4661707818cfd92556e7fdf9068a993577002.zip cpython-2cb4661707818cfd92556e7fdf9068a993577002.tar.gz cpython-2cb4661707818cfd92556e7fdf9068a993577002.tar.bz2 |
bpo-33034: Improve exception message when cast fails for {Parse,Split}Result.port (GH-6078)
Diffstat (limited to 'Lib/urllib/parse.py')
-rw-r--r-- | Lib/urllib/parse.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py index 58460f9..3f8cfe5 100644 --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -166,7 +166,11 @@ class _NetlocResultMixinBase(object): def port(self): port = self._hostinfo[1] if port is not None: - port = int(port, 10) + try: + port = int(port, 10) + except ValueError: + message = f'Port could not be cast to integer value as {port!r}' + raise ValueError(message) from None if not ( 0 <= port <= 65535): raise ValueError("Port out of range 0-65535") return port |