From 2cb4661707818cfd92556e7fdf9068a993577002 Mon Sep 17 00:00:00 2001 From: Matt Eaton Date: Tue, 20 Mar 2018 01:41:37 -0500 Subject: bpo-33034: Improve exception message when cast fails for {Parse,Split}Result.port (GH-6078) --- Lib/urllib/parse.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'Lib/urllib/parse.py') diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py index 58460f9234..3f8cfe5300 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 -- cgit v1.2.1