betty.fetch package

Submodules

Module contents

Fetch content from the internet.

exception betty.fetch.FetchError[source]

Bases: UserFacingError, RuntimeError

An error that occurred when fetching a URL.

final class betty.fetch.FetchResponse[source]

Bases: object

An HTTP response.

__init__(headers: CIMultiDict[str], body: bytes, encoding: str) None
body: bytes
encoding: str
headers: CIMultiDict[str]
property json: Any

The body as JSON.

This may raise an error if the response body cannot be represented as JSON or plain text.

property text: str

The body as plain text.

This may raise an error if the response body cannot be represented as plain text.

class betty.fetch.Fetcher[source]

Bases: ABC

Fetch content from the internet.

abstractmethod async fetch(url: str) FetchResponse[source]

Fetch an HTTP resource.

Raises:

FetchError – if an error occurred while fetching the content.

abstractmethod async fetch_file(url: str) Path[source]

Fetch a file.

Raises:

FetchError – if an error occurred while fetching the content.

Returns:

The path to the file on disk.