Skip to content

session_config

get_session_defaults()

Get the current default values for session configuration.

Returns:

Type Description
dict

Dictionary of current default values for session configuration.

set_session_defaults(max_retries=3, pool_block=False, pool_maxsize=10, backoff_factor=0.1, backoff_max=120, status_forcelist=(502, 503, 504))

Set global default values to configure how all clients will communicate with servers. Should be done prior to initializing a client.

Note that these values are only used when not set at the client level.

Parameters:

Name Type Description Default
max_retries int

The maximum number of retries each connection should attempt. Set to 0 to fail on the first retry.

3
pool_block bool

Whether the connection pool should block for connections.

False
pool_maxsize int

The maximum number of connections to save in the pool.

10
backoff_factor Union[float, int]

A backoff factor to apply between attempts after the second try (most errors are resolved immediately by a second try without a delay). The query will sleep for: {backoff factor} * (2 ^ ({number of total retries} - 1)) seconds. For example, if the backoff_factor is 0.1, then will sleep for [0.0s, 0.2s, 0.4s, 0.8s, …] between retries. No backoff will ever be longer than backoff_max.

0.1
backoff_max Union[float, int]

The maximum backoff time.

120
status_forcelist Optional[Collection]

A set of integer HTTP status codes that we should force a retry on.

(502, 503, 504)
Usage
from caveclient import set_session_defaults

set_session_defaults(
    max_retries=5, # would increase the default number of retries
    backoff_factor=0.5, # would increase the default backoff factor between retries
    backoff_max=240, # would increase the default maximum backoff time
    status_forcelist=(502, 503, 504, 505), # would add 505 to the default list
)

set_session_defaults() # would revert all defaults to their original values
Notes

Calling this function will set the default values for all clients created after the call.

Calling this function with any arguments missing will reset that value to the default value.

See Also:

urllib3.util.Retry

requests.adapters.HTTPAdapter