From 8a6bcfbe1a3eac55b3f1bbf62469c33b9ec87222 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 15 Mar 2018 10:41:26 -0400 Subject: [PATCH] validate Signed-off-by: Kenneth Reitz --- requests/models.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/requests/models.py b/requests/models.py index 19bcd073..2608e246 100644 --- a/requests/models.py +++ b/requests/models.py @@ -391,7 +391,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): return host - def prepare_url(self, url, params): + def prepare_url(self, url, params, validate=False): """Prepares the given HTTP URL.""" # : Accept objects that have string representations. #: We're unable to blindly call unicode/str functions @@ -414,13 +414,11 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): # Support for unicode domain names and paths. try: uri = rfc3986.urlparse(url) - rfc3986.normalize_uri(url) + if validate: + rfc3986.normalize_uri(url) except rfc3986.exceptions.RFC3986Exception: raise InvalidURL("Invalid URL %r: URL is imporoper." % url) - - - if not uri.scheme: error = ( "Invalid URL {0!r}: No scheme supplied. Perhaps you meant http://{0}?"