How to use the httpx.exceptions.HTTPError function in httpx

To help you get started, weā€™ve selected a few httpx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github encode / httpx / httpx / exceptions.py View on Github external
# Other cases...


class InvalidURL(HTTPError):
    """
    URL was missing a hostname, or was not one of HTTP/HTTPS.
    """


class ConnectionClosed(HTTPError):
    """
    Expected more data from peer, but connection was closed.
    """


class CookieConflict(HTTPError):
    """
    Attempted to lookup a cookie by name, but multiple cookies existed.
github encode / httpx / httpx / exceptions.py View on Github external
class PoolTimeout(TimeoutException):
    """
    Timeout while waiting to acquire a connection from the pool.
    """


class ProxyError(HTTPError):
    """
    Error from within a proxy
    """


# HTTP exceptions...


class ProtocolError(HTTPError):
    """
    Malformed HTTP.
    """


class DecodingError(HTTPError):
    """
    Decoding of the response failed.
    """


# Redirect exceptions...


class RedirectError(HTTPError):
    """
github encode / httpx / httpx / exceptions.py View on Github external
class RedirectLoop(RedirectError):
    """
    Infinite redirect loop.
    """


class NotRedirectResponse(RedirectError):
    """
    Response was not a redirect response.
    """


# Stream exceptions...


class StreamError(HTTPError):
    """
    The base class for stream exceptions.

    The developer made an error in accessing the request stream in
    an invalid way.
    """


class StreamConsumed(StreamError):
    """
    Attempted to read or stream response content, but the content has already
    been streamed.
    """


class ResponseNotRead(StreamError):
github encode / httpx / httpx / models.py View on Github external
def raise_for_status(self) -> None:
        """
        Raise the `HttpError` if one occurred.
        """
        message = (
            "{0.status_code} {error_type}: {0.reason_phrase} for url: {0.url}\n"
            "For more information check: https://httpstatuses.com/{0.status_code}"
        )

        if StatusCode.is_client_error(self.status_code):
            message = message.format(self, error_type="Client Error")
            raise HTTPError(message, response=self)
        elif StatusCode.is_server_error(self.status_code):
            message = message.format(self, error_type="Server Error")
            raise HTTPError(message, response=self)
github encode / httpx / httpx / client.py View on Github external
cert: CertTypes = None,
    ) -> Response:
        """
        Sends a single request, without handling any redirections.
        """

        dispatcher = self.dispatcher_for_url(request.url)

        try:
            with ElapsedTimer() as timer:
                response = await dispatcher.send(
                    request, verify=verify, cert=cert, timeout=timeout
                )
            response.elapsed = timer.elapsed
            response.request = request
        except HTTPError as exc:
            # Add the original request to any HTTPError unless
            # there'a already a request attached in the case of
            # a ProxyError.
            if exc.request is None:
                exc.request = request
            raise

        self.cookies.extract_cookies(response)

        status = f"{response.status_code} {response.reason_phrase}"
        response_line = f"{response.http_version} {status}"
        logger.debug(f'HTTP Request: {request.method} {request.url} "{response_line}"')

        return response
github checktheroads / hyperglass / hyperglass / execution / execute.py View on Github external
decoded = await jwt_decode(
                            payload=raw_response.json()["encoded"],
                            secret=self.device.credential.password.get_secret_value(),
                        )
                        log.debug(f"Decoded Response: {decoded}")
                        responses += (decoded,)
                    elif raw_response.status_code == 204:
                        raise ResponseEmpty(
                            params.messages.no_output,
                            device_name=self.device.display_name,
                        )

                    else:
                        log.error(raw_response.text)

        except httpx.exceptions.HTTPError as rest_error:
            msg = parse_exception(rest_error)
            log.error(f"Error connecting to device {self.device.name}: {msg}")
            raise RestError(
                params.messages.connection_error,
                device_name=self.device.display_name,
                error=msg,
            )
        except OSError as ose:
            log.critical(str(ose))
            raise RestError(
                params.messages.connection_error,
                device_name=self.device.display_name,
                error="System error",
            )
        except CertificateError as cert_error:
            log.critical(str(cert_error))
github encode / httpx / httpx / exceptions.py View on Github external
class ProxyError(HTTPError):
    """
    Error from within a proxy
    """


# HTTP exceptions...


class ProtocolError(HTTPError):
    """
    Malformed HTTP.
    """


class DecodingError(HTTPError):
    """
    Decoding of the response failed.
    """


# Redirect exceptions...


class RedirectError(HTTPError):
    """
    Base class for HTTP redirect errors.
    """


class TooManyRedirects(RedirectError):
    """
github encode / httpx / httpx / exceptions.py View on Github external
class ProtocolError(HTTPError):
    """
    Malformed HTTP.
    """


class DecodingError(HTTPError):
    """
    Decoding of the response failed.
    """


# Redirect exceptions...


class RedirectError(HTTPError):
    """
    Base class for HTTP redirect errors.
    """


class TooManyRedirects(RedirectError):
    """
    Too many redirects.
    """


class RedirectBodyUnavailable(RedirectError):
    """
    Got a redirect response, but the request body was streaming, and is
    no longer available.
    """
github encode / httpx / httpx / exceptions.py View on Github external
"""


class WriteTimeout(TimeoutException):
    """
    Timeout while writing request data.
    """


class PoolTimeout(TimeoutException):
    """
    Timeout while waiting to acquire a connection from the pool.
    """


class ProxyError(HTTPError):
    """
    Error from within a proxy
    """


# HTTP exceptions...


class ProtocolError(HTTPError):
    """
    Malformed HTTP.
    """


class DecodingError(HTTPError):
    """
github encode / httpx / httpx / exceptions.py View on Github external
"""
    Base class for all httpx exceptions.
    """

    def __init__(
        self, *args: typing.Any, request: "Request" = None, response: "Response" = None
    ) -> None:
        self.response = response
        self.request = request or getattr(self.response, "request", None)
        super().__init__(*args)


# Timeout exceptions...


class TimeoutException(HTTPError):
    """
    A base class for all timeouts.
    """


class ConnectTimeout(TimeoutException):
    """
    Timeout while establishing a connection.
    """


class ReadTimeout(TimeoutException):
    """
    Timeout while reading response data.
    """