Skip to content
Myr

exceptions.py

This file

Path

requests/exceptions.py

126 lines · 3.1 KiB · Python

Last changed by

Merge pull request #4356 from nehaljwani/fix-4353Nate Prewittbefore adoptiond55de2d

History of this file

Take it

1# -*- coding: utf-8 -*-23"""4requests.exceptions5~~~~~~~~~~~~~~~~~~~67This module contains the set of Requests' exceptions.8"""9from urllib3.exceptions import HTTPError as BaseHTTPError101112class RequestException(IOError):13    """There was an ambiguous exception that occurred while handling your14    request.15    """1617    def __init__(self, *args, **kwargs):18        """Initialize RequestException with `request` and `response` objects."""19        response = kwargs.pop('response', None)20        self.response = response21        self.request = kwargs.pop('request', None)22        if (response is not None and not self.request and23                hasattr(response, 'request')):24            self.request = self.response.request25        super(RequestException, self).__init__(*args, **kwargs)262728class HTTPError(RequestException):29    """An HTTP error occurred."""303132class ConnectionError(RequestException):33    """A Connection error occurred."""343536class ProxyError(ConnectionError):37    """A proxy error occurred."""383940class SSLError(ConnectionError):41    """An SSL error occurred."""424344class Timeout(RequestException):45    """The request timed out.4647    Catching this error will catch both48    :exc:`~requests.exceptions.ConnectTimeout` and49    :exc:`~requests.exceptions.ReadTimeout` errors.50    """515253class ConnectTimeout(ConnectionError, Timeout):54    """The request timed out while trying to connect to the remote server.5556    Requests that produced this error are safe to retry.57    """585960class ReadTimeout(Timeout):61    """The server did not send any data in the allotted amount of time."""626364class URLRequired(RequestException):65    """A valid URL is required to make a request."""666768class TooManyRedirects(RequestException):69    """Too many redirects."""707172class MissingSchema(RequestException, ValueError):73    """The URL schema (e.g. http or https) is missing."""747576class InvalidSchema(RequestException, ValueError):77    """See defaults.py for valid schemas."""787980class InvalidURL(RequestException, ValueError):81    """The URL provided was somehow invalid."""828384class InvalidHeader(RequestException, ValueError):85    """The header value provided was somehow invalid."""868788class InvalidProxyURL(InvalidURL):89    """The proxy URL provided is invalid."""909192class ChunkedEncodingError(RequestException):93    """The server declared chunked encoding but sent an invalid chunk."""949596class ContentDecodingError(RequestException, BaseHTTPError):97    """Failed to decode response content"""9899100class StreamConsumedError(RequestException, TypeError):101    """The content for this response was already consumed"""102103104class RetryError(RequestException):105    """Custom retries logic failed"""106107108class UnrewindableBodyError(RequestException):109    """Requests encountered an error when trying to rewind a body"""110111# Warnings112113114class RequestsWarning(Warning):115    """Base warning for Requests."""116    pass117118119class FileModeWarning(RequestsWarning, DeprecationWarning):120    """A file was opened in text mode, but Requests determined its binary length."""121    pass122123124class RequestsDependencyWarning(RequestsWarning):125    """An imported dependency doesn't match the expected version range."""126    pass