Skip to content
Myr

exceptions.py

This file

Path

requests/exceptions.py

114 lines · 2.7 KiB · Python

Last changed by

Merge pull request #2825 from Lukasa/universal_newlinesIan Cordascobefore adoptiond290a9b

History of this file

Take it

1# -*- coding: utf-8 -*-23"""4requests.exceptions5~~~~~~~~~~~~~~~~~~~67This module contains the set of Requests' exceptions.89"""10from .packages.urllib3.exceptions import HTTPError as BaseHTTPError111213class RequestException(IOError):14    """There was an ambiguous exception that occurred while handling your15    request."""1617    def __init__(self, *args, **kwargs):18        """19        Initialize RequestException with `request` and `response` objects.20        """21        response = kwargs.pop('response', None)22        self.response = response23        self.request = kwargs.pop('request', None)24        if (response is not None and not self.request and25                hasattr(response, 'request')):26            self.request = self.response.request27        super(RequestException, self).__init__(*args, **kwargs)282930class HTTPError(RequestException):31    """An HTTP error occurred."""323334class ConnectionError(RequestException):35    """A Connection error occurred."""363738class ProxyError(ConnectionError):39    """A proxy error occurred."""404142class SSLError(ConnectionError):43    """An SSL error occurred."""444546class Timeout(RequestException):47    """The request timed out.4849    Catching this error will catch both50    :exc:`~requests.exceptions.ConnectTimeout` and51    :exc:`~requests.exceptions.ReadTimeout` errors.52    """535455class ConnectTimeout(ConnectionError, Timeout):56    """The request timed out while trying to connect to the remote server.5758    Requests that produced this error are safe to retry.59    """606162class ReadTimeout(Timeout):63    """The server did not send any data in the allotted amount of time."""646566class URLRequired(RequestException):67    """A valid URL is required to make a request."""686970class TooManyRedirects(RequestException):71    """Too many redirects."""727374class MissingSchema(RequestException, ValueError):75    """The URL schema (e.g. http or https) is missing."""767778class InvalidSchema(RequestException, ValueError):79    """See defaults.py for valid schemas."""808182class InvalidURL(RequestException, ValueError):83    """ The URL provided was somehow invalid. """848586class ChunkedEncodingError(RequestException):87    """The server declared chunked encoding but sent an invalid chunk."""888990class ContentDecodingError(RequestException, BaseHTTPError):91    """Failed to decode response content"""929394class StreamConsumedError(RequestException, TypeError):95    """The content for this response was already consumed"""969798class RetryError(RequestException):99    """Custom retries logic failed"""100101102# Warnings103104105class RequestsWarning(Warning):106    """Base warning for Requests."""107    pass108109110class FileModeWarning(RequestsWarning, DeprecationWarning):111    """112    A file was opened in text mode, but Requests determined its binary length.113    """114    pass