Skip to content
Myr

Merge pull request #548 from umbrae/httperror_fix

Before adoption: this commit came in with the history the project adopted, so no landing records it.

A get with an invalid port should wrap urllib3's LocationParseError exception with our own.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 8a055c5, 3a2eaa6 · Browse files · 3 files+21 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+21 added−8 removed

  • tests:+7 added−0 removed
  • other:+14 added−8 removed

3 files+21 added−8 removed

modified:requests/exceptions.py+4 added-1 removed
33 unmodified lines
34class MissingSchema(RequestException, ValueError):35 """The URL schema (e.g. http or https) is missing."""3637class InvalidSchema(RequestException, ValueError):38 """See defaults.py for valid schemas."""38 """See defaults.py for valid schemas."""39 40class InvalidURL(RequestException, ValueError):41 """ The URL provided was somehow invalid. """
modified:requests/models.py+10 added-7 removed
14 unmodified lines
15from .status_codes import codes1617from .auth import HTTPBasicAuth, HTTPProxyAuth18from .packages.urllib3.response import HTTPResponse19from .packages.urllib3.exceptions import MaxRetryError19from .packages.urllib3.exceptions import MaxRetryError, LocationParseError20from .packages.urllib3.exceptions import SSLError as _SSLError21from .packages.urllib3.exceptions import HTTPError as _HTTPError22from .packages.urllib3 import connectionpool, poolmanager23from .packages.urllib3.filepost import encode_multipart_formdata24from .defaults import SCHEMAS25from .exceptions import (26 ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,27 URLRequired, SSLError, MissingSchema, InvalidSchema)27 URLRequired, SSLError, MissingSchema, InvalidSchema, InvalidURL)28from .utils import (29 get_encoding_from_headers, stream_untransfer, guess_filename, requote_uri,30 dict_from_string, stream_decode_response_unicode, get_netrc_auth)31from .compat import (
464 unmodified lines
496 r = self.proxy_auth(self)497 self.__dict__.update(r.__dict__)498 else:499 # Check to see if keep_alive is allowed.500 try:500 if self.config.get('keep_alive'):501 conn = self._poolmanager.connection_from_url(url)502 else:503 conn = connectionpool.connection_from_url(url)504501 if self.config.get('keep_alive'):502 conn = self._poolmanager.connection_from_url(url)503 else:504 conn = connectionpool.connection_from_url(url)505 except LocationParseError as e:506 raise InvalidURL(e)507 508 if url.startswith('https') and self.verify:509510 cert_loc = None511
310 unmodified lines
modified:tests/test_requests.py+7 added
779 unmodified lines
780 def test_upload_binary_data(self):781782 requests.get(httpbin('post'), auth=('a', 'b'), data='\xff')783784 def test_useful_exception_for_invalid_port(self):785 # If we pass a legitimate URL with an invalid port, we should fail.786 self.assertRaises(787 ValueError,788 get,789 'http://google.com:banana')790791 def test_useful_exception_for_invalid_scheme(self):792793 # If we pass a legitimate URL with a scheme not supported794 # by requests, we should fail.
29 unmodified lines