betty.fetch module

Fetch content from the internet.

exception betty.fetch.FetchError[source]

Bases: UserFacingError, RuntimeError

An error that occurred when fetching a URL.

Parameters:

message (betty.locale.Localizable)

class betty.fetch.FetchResponse[source]

Bases: object

An HTTP response.

Parameters:
  • headers (multidict._multidict.CIMultiDict[str])

  • body (bytes)

  • encoding (str)

__init__(headers: multidict._multidict.CIMultiDict[str], body: bytes, encoding: str) None
Parameters:
  • headers (multidict._multidict.CIMultiDict[str])

  • body (bytes)

  • encoding (str)

body: bytes
encoding: str
headers: multidict._multidict.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: object

Fetch content from the internet.

Parameters:
__init__(http_client: aiohttp.client.ClientSession, response_cache: betty.cache.Cache[betty.fetch.FetchResponse], binary_file_cache: betty.cache.file.BinaryFileCache, ttl: int = 604800)[source]
Parameters:
async fetch(url: str) betty.fetch.FetchResponse[source]

Fetch an HTTP resource.

Parameters:

url (str)

Return type:

betty.fetch.FetchResponse

async fetch_file(url: str) pathlib.Path[source]

Fetch a file.

Return type:

pathlib.Path

Returns:

The path to the file on disk.

Parameters:

url (str)