corehttp.transport.requests package

class corehttp.transport.requests.RequestsTransport(**kwargs)[source]

Implements a basic requests HTTP sender.

Since requests team recommends to use one session per requests, you should not consider this class as thread-safe, since it will use one Session per instance.

In this simple implementation: - You provide the configured session if you want to, or a basic session is created. - All kwargs received by “send” are sent to session.request directly

Keyword Arguments:
  • session (requests.Session) – Request session to use instead of the default one.

  • session_owner (bool) – Decide if the session provided by user is owned by this transport. Default to True.

  • use_env_settings (bool) – Uses proxy settings from environment. Defaults to True.

close()[source]

Close the session if it is not externally owned.

open()[source]

Assign new session if one does not already exist.

send(request: RestHttpRequest, *, stream: bool = False, proxies: MutableMapping[str, str] | None = None, **kwargs) RestHttpResponse[source]

Send request object according to configuration.

Parameters:

request (HttpRequest) – The request object to be sent.

Keyword Arguments:
  • stream (bool) – Defaults to False.

  • proxies (MutableMapping) – dict of proxies to use based on protocol. Proxy is a dict (protocol, url).

Returns:

An HTTPResponse object.

Return type:

HttpResponse

sleep(duration: float) None

Sleep for the specified duration.

You should always ask the transport to sleep, and not call directly the stdlib. This is mostly important in async, as the transport may not use asyncio but other implementations like trio and they have their own way to sleep, but to keep design consistent, it’s cleaner to always ask the transport to sleep and let the transport implementor decide how to do it.

Parameters:

duration (float) – The number of seconds to sleep.