diff --git a/requests/exceptions.py b/requests/exceptions.py index d5b2ab17..3c262e36 100644 --- a/requests/exceptions.py +++ b/requests/exceptions.py @@ -30,3 +30,9 @@ class URLRequired(RequestException): class TooManyRedirects(RequestException): """Too many redirects.""" + +class MissingSchema(RequestException, ValueError): + """The URL schema (e.g. http or https) is missing.""" + +class InvalidSchema(RequestException, ValueError): + """See defaults.py for valid schemas.""" \ No newline at end of file diff --git a/requests/models.py b/requests/models.py index 753e83ab..64bc42c1 100644 --- a/requests/models.py +++ b/requests/models.py @@ -24,7 +24,7 @@ from .packages.urllib3.filepost import encode_multipart_formdata from .defaults import SCHEMAS from .exceptions import ( ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects, - URLRequired, SSLError) + URLRequired, SSLError, MissingSchema, InvalidSchema) from .utils import ( get_encoding_from_headers, stream_untransfer, guess_filename, requote_uri, dict_from_string, stream_decode_response_unicode, get_netrc_auth) @@ -321,10 +321,10 @@ class Request(object): scheme, netloc, path, params, query, fragment = urlparse(url) if not scheme: - raise ValueError("Invalid URL %r: No schema supplied" % url) + raise MissingSchema("Invalid URL %r: No schema supplied" % url) if not scheme in SCHEMAS: - raise ValueError("Invalid scheme %r" % scheme) + raise InvalidSchema("Invalid scheme %r" % scheme) netloc = netloc.encode('idna').decode('utf-8')