diff --git a/aiohttp/client.py b/aiohttp/client.py index 5a2bc57cb0e..d19855b350f 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -345,8 +345,8 @@ async def _request( try: url = URL(str_or_url) - except ValueError: - raise InvalidURL(str_or_url) + except ValueError as e: + raise InvalidURL(str_or_url) from e skip_headers = set(self._skip_auto_headers) if skip_auto_headers is not None: @@ -356,8 +356,8 @@ async def _request( if proxy is not None: try: proxy = URL(proxy) - except ValueError: - raise InvalidURL(proxy) + except ValueError as e: + raise InvalidURL(proxy) from e if timeout is sentinel: real_timeout = self._timeout # type: ClientTimeout @@ -529,8 +529,8 @@ async def _request( parsed_url = URL( r_url, encoded=not self._requote_redirect_url) - except ValueError: - raise InvalidURL(r_url) + except ValueError as e: + raise InvalidURL(r_url) from e scheme = parsed_url.scheme if scheme not in ('http', 'https', ''): @@ -777,7 +777,7 @@ async def _ws_connect( resp.history, message=exc.args[0], status=resp.status, - headers=resp.headers) + headers=resp.headers) from exc else: compress = 0 notakeover = False