Skip to content

sybaritic.response

Response dataclass

Response(
    uri: SpartanURI,
    status: Status,
    meta: str,
    content: bytes = b"",
    requested_uri: SpartanURI | None = None,
    history: list[Response] = list(),
)

Represents a response from a Spartan server.

Attributes:

Name Type Description
uri SpartanURI

The final SpartanURI of the response.

status Status

The response status code enum.

meta str

Metadata string from status line (mimetype, redirect path, or error message).

content bytes

Raw response body bytes.

requested_uri SpartanURI | None

The originally requested SpartanURI (before redirects).

history list[Response]

List of intermediate Response objects leading to this response via redirects.

charset property

charset: str

Return the character encoding (alias for encoding).

encoding property

encoding: str

Return the character encoding extracted from mimetype parameters, defaulting to 'utf-8'.

error_message property

error_message: str | None

Return the error message if status is 4 or 5, otherwise None.

is_client_error property

is_client_error: bool

Return True if response is status 4 (Client Error).

is_error property

is_error: bool

Return True if response is status 4 or 5.

is_redirect property

is_redirect: bool

Return True if response is status 3 (Redirect).

is_redirected property

is_redirected: bool

Return True if this response is the result of following redirects.

is_server_error property

is_server_error: bool

Return True if response is status 5 (Server Error).

is_success property

is_success: bool

Return True if response is status 2 (Success).

mimetype property

mimetype: str

Return the MIME type for a successful response (without parameters).

redirect_path property

redirect_path: str | None

Return the target redirect path if status is 3, otherwise None.

text property

text: str

Return the response body decoded as a string using the response encoding.

raise_for_status

raise_for_status() -> None

Raise ClientError or ServerError if status code indicates an error.