diff --git a/aiohttp/client.py b/aiohttp/client.py index 7a4db0db476..3b825d02f6f 100644 --- a/aiohttp/client.py +++ b/aiohttp/client.py @@ -345,8 +345,8 @@ def request( """Perform HTTP request.""" return _RequestContextManager(self._request(method, url, **kwargs)) - def _build_url(self, str_or_url: StrOrURL) -> URL: - url = URL(str_or_url) + def _build_url(self, str_or_url: StrOrURL, **kwargs: Any) -> URL: + url = URL(str_or_url, encoded=kwargs.get("encode_url")) if self._base_url is None: return url else: @@ -385,6 +385,7 @@ async def _request( auto_decompress: Optional[bool] = None, max_line_size: Optional[int] = None, max_field_size: Optional[int] = None, + encode_url: Optional[bool] = False, ) -> ClientResponse: # NOTE: timeout clamps existing connect and read timeouts. We cannot # set the default to None because we need to detect if the user wants @@ -416,7 +417,7 @@ async def _request( proxy_headers = self._prepare_headers(proxy_headers) try: - url = self._build_url(str_or_url) + url = self._build_url(str_or_url, encode_url=encode_url) except ValueError as e: raise InvalidUrlClientError(str_or_url) from e