1515from . import connector as connector_mod
1616from . import client_exceptions , client_reqrep , hdrs , http , payload
1717from .client_exceptions import * # noqa
18- from .client_exceptions import (ClientError , ClientOSError , ServerTimeoutError ,
19- WSServerHandshakeError )
18+ from .client_exceptions import (ClientError , ClientOSError , InvalidURL ,
19+ ServerTimeoutError , WSServerHandshakeError )
2020from .client_reqrep import * # noqa
2121from .client_reqrep import ClientRequest , ClientResponse
2222from .client_ws import ClientWebSocketResponse
@@ -204,7 +204,15 @@ def _request(self, method, url, *,
204204 skip_headers .add (istr (i ))
205205
206206 if proxy is not None :
207- proxy = URL (proxy )
207+ try :
208+ proxy = URL (proxy )
209+ except ValueError :
210+ raise InvalidURL (url )
211+
212+ try :
213+ url = URL (url )
214+ except ValueError :
215+ raise InvalidURL (url )
208216
209217 # timeout is cumulative for all request operations
210218 # (request, redirects, responses, data consuming)
@@ -217,7 +225,7 @@ def _request(self, method, url, *,
217225 try :
218226 with timer :
219227 while True :
220- url = URL ( url ) .with_fragment (None )
228+ url = url .with_fragment (None )
221229 cookies = self ._cookie_jar .filter_cookies (url )
222230
223231 req = self ._request_class (
@@ -285,8 +293,12 @@ def _request(self, method, url, *,
285293 # see github.com/aio-libs/aiohttp/issues/2022
286294 break
287295
288- r_url = URL (
289- r_url , encoded = not self .requote_redirect_url )
296+ try :
297+ r_url = URL (
298+ r_url , encoded = not self .requote_redirect_url )
299+
300+ except ValueError :
301+ raise InvalidURL (r_url )
290302
291303 scheme = r_url .scheme
292304 if scheme not in ('http' , 'https' , '' ):
0 commit comments