hdx.utilities.session
Session utilities for urls.
get_session
def get_session(user_agent: Optional[str] = None,
user_agent_config_yaml: Optional[str] = None,
user_agent_lookup: Optional[str] = None,
use_env: bool = True,
fail_on_missing_file: bool = True,
verify: bool = True,
retry_attempts: int = 5,
backoff_factor: int = 1,
**kwargs: Any) -> requests.Session
Set up and return Session object that is set up with retrying. Requires either global user agent to be set or appropriate user agent parameter(s) to be completed. If the EXTRA_PARAMS, BASIC_AUTH or BEARER_TOKEN environment variable is supplied, the extra_params* parameters will be ignored.
Arguments:
user_agent
Optional[str] - User agent string. HDXPythonUtilities/X.X.X- is prefixed.user_agent_config_yaml
Optional[str] - Path to YAML user agent configuration. Ignored if user_agent supplied. Defaults to ~/.useragent.yaml.user_agent_lookup
Optional[str] - Lookup key for YAML. Ignored if user_agent supplied.use_env
bool - Whether to read environment variables. Defaults to True.fail_on_missing_file
bool - Raise an exception if any specified configuration files are missing. Defaults to True.verify
bool - Whether to verify SSL certificates. Defaults to True.retry_attempts
int - Number of retry attempts. Defaults to 5.backoff_factor
int - Backoff factor for retry. Defaults to 1 (0s, 2s, 4s, 8s, 16s, 32s).**kwargs
- See belowauth
Tuple[str, str] - Authorisation information in tuple form (user, pass) ORbasic_auth
str - Authorisation information in basic auth string form (Basic xxxxxxxxxxxxxxxx) ORbasic_auth_file
str - Path to file containing authorisation information in basic auth string form (Basic xxxxxxxxxxxxxxxx) ORbearer_token
str - Bearer token string ORbearer_token_file
str - Path to file containing bearer token string ORextra_params_dict
Dict - Extra parameters to put on end of url as a dictionary ORextra_params_json
str - Path to JSON file containing extra parameters to put on end of url ORextra_params_yaml
str - Path to YAML file containing extra parameters to put on end of urlextra_params_lookup
str - Lookup key for parameters. If not given assumes parameters are at root of the dict.headers
Dict - Additional headers to add to request.use_auth
str - If more than one auth found, specify which one to use, rather than failing.status_forcelist
ListTuple[int] - HTTP statuses for which to force retry. Defaults to (429, 500, 502, 503, 504).allowed_methods
ListTuple[str] - HTTP methods for which to force retry. Defaults to ("HEAD", "TRACE", "GET", "PUT", "OPTIONS", "DELETE").