findmy.util.http

Module to simplify asynchronous HTTP calls.

Classes

HttpResponse

Response of a request made by HttpSession.

HttpSession

Asynchronous HTTP session manager. For internal use only.

Module Contents

class findmy.util.http.HttpResponse(status_code: int, content: bytes)

Response of a request made by HttpSession.

property status_code: int

HTTP status code of the response.

property ok: bool

Whether the status code is “OK” (2xx).

text() str

Response content as a UTF-8 encoded string.

json() dict[Any, Any]

Response content as a dict, obtained by JSON-decoding the response content.

plist() dict[Any, Any]

Response content as a dict, obtained by Plist-decoding the response content.

class findmy.util.http.HttpSession

Bases: findmy.util.closable.Closable

Asynchronous HTTP session manager. For internal use only.

async close() None

Close the underlying session. Should be called when session will no longer be used.

async request(method: str, url: str, **kwargs: typing_extensions.Unpack[_HttpRequestOptions]) HttpResponse

Make an HTTP request.

Keyword arguments will directly be passed to aiohttp.ClientSession.request.

async get(url: str, **kwargs: typing_extensions.Unpack[_HttpRequestOptions]) HttpResponse

Alias for HttpSession.request(“GET”, …).

async post(url: str, **kwargs: typing_extensions.Unpack[_HttpRequestOptions]) HttpResponse

Alias for HttpSession.request(“POST”, …).