Skip to content

Transport

HTTP transport construction shared by the authorised and unauthorised sessions.

Functions:

  • build_transport – Return a retrying transport with TCP keepalive enabled on its connections.
  • keepalive_socket_options – Socket options that make the OS probe an idle connection and drop a dead peer.

build_transport

build_transport(retries, *, timeout=None, is_async=False)

Return a retrying transport with TCP keepalive enabled on its connections.

Parameters:

  • retries (Retry) – The retry policy.
  • timeout (float | Timeout | None) – Timeout for requests that do not carry their own. None adds none.
  • is_async (bool) – Build an async transport.

keepalive_socket_options

keepalive_socket_options()

Socket options that make the OS probe an idle connection and drop a dead peer.

A reader blocked on a silent connection sends nothing, so without probes the kernel never notices a peer that vanished without a FIN or RST (load balancer idle timeout, pod replaced mid-request, conntrack eviction). With these settings a dead peer surfaces as ETIMEDOUT after roughly two minutes instead of the Linux default of over two hours.

Options a platform lacks are skipped rather than raised on: TCP_KEEPIDLE is named TCP_KEEPALIVE on macOS, and older Windows Pythons have neither it nor the others.

Back to top