# keystoneauth1.session module

class keystoneauth1.session.NoOpSemaphore

  Bases: `object`

  Empty context manager for use as a default semaphore.

  __annotate_func__ = None
  __annotations_cache__ = {}
  __dict__ = mappingproxy({'__module__': 'keystoneauth1.session', '__firstlineno__': 114, '__doc__': 'Empty context manager for use as a default semaphore.', '__enter__': <function NoOpSemaphore.__enter__>, '__exit__': <function NoOpSemaphore.__exit__>, '__static_attributes__': (), '__dict__': <attribute '__dict__' of 'NoOpSemaphore' objects>, '__weakref__': <attribute '__weakref__' of 'NoOpSemaphore' objects>, '__annotate_func__': None, '__annotations_cache__': {}})
  __doc__ = 'Empty context manager for use as a default semaphore.'
  __enter__() → None

    Enter the context manager and do nothing.

  __exit__(exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) → None

    Exit the context manager and do nothing.

  __firstlineno__ = 114
  __module__ = 'keystoneauth1.session'
  __static_attributes__ = ()
  __weakref__

    list of weak references to the object

class keystoneauth1.session.RequestTiming(method: str | None, url: str | None, elapsed: timedelta)

  Bases: `object`

  Contains timing information for an HTTP interaction.

  __annotations_cache__ = {'elapsed': <class 'datetime.timedelta'>, 'method': str | None, 'url': str | None}
  __dict__ = mappingproxy({'__module__': 'keystoneauth1.session', '__firstlineno__': 246, '__doc__': 'Contains timing information for an HTTP interaction.', '__init__': <function RequestTiming.__init__>, '__static_attributes__': ('elapsed', 'method', 'url'), '__dict__': <attribute '__dict__' of 'RequestTiming' objects>, '__weakref__': <attribute '__weakref__' of 'RequestTiming' objects>, '__annotations_cache__': {'method': str | None, 'url': str | None, 'elapsed': <class 'datetime.timedelta'>}})
  __doc__ = 'Contains timing information for an HTTP interaction.'
  __firstlineno__ = 246
  __init__(method: str | None, url: str | None, elapsed: timedelta)
  __module__ = 'keystoneauth1.session'
  __static_attributes__ = ('elapsed', 'method', 'url')
  __weakref__

    list of weak references to the object

  elapsed: timedelta

    Elapsed time information

  method: str | None

    HTTP method used for the call (GET, POST, etc)

  url: str | None

    URL against which the call was made

class keystoneauth1.session.Session(auth: plugin.BaseAuthPlugin | None = None, session: Session | None = None, original_ip: str | None = None, verify: bool | str | None = True, cert: str | tuple[str, str] | None = None, timeout: float | int | None = None, user_agent: str | None = None, redirect: int | bool = 30, additional_headers: MutableMapping[str, str] | None = None, app_name: str | None = None, app_version: str | None = None, additional_user_agent: list[tuple[str, str]] | None = None, discovery_cache: dict[str, Any] | None = None, split_loggers: bool | None = None, collect_timing: bool = False, rate_semaphore: ContextManager[None, bool | None] | None = None, connect_retries: int = 0)

  Bases: `object`

  Maintains client communication state and common functionality.

  As much as possible the parameters to this class reflect and are passed directly to the `requests` library.

  Parameters:

    - auth (keystoneauth1.plugin.BaseAuthPlugin) – An authentication plugin to authenticate the session with. (optional, defaults to None)

    - session (requests.Session) – A requests session object that can be used for issuing requests. (optional)

    - original_ip (str) – The original IP of the requesting user which will be sent to identity service in a ‘Forwarded’ header. (optional)

    - verify – The verification arguments to pass to requests. These are of the same form as requests expects, so True or False to verify (or not) against system certificates or a path to a bundle or CA certs to check against or None for requests to attempt to locate and use certificates. (optional, defaults to True)

    - cert – A client certificate to pass to requests. These are of the same form as requests expects. Either a single filename containing both the certificate and key or a tuple containing the path to the certificate then a path to the key. (optional)

    - timeout (float) – A timeout to pass to requests. This should be a numerical value indicating some amount (or fraction) of seconds or 0 for no timeout. (optional, defaults to 0)

    - user_agent (str) – A User-Agent header string to use for the request. If not provided, a default of `DEFAULT_USER_AGENT` is used, which contains the keystoneauth1 version as well as those of the requests library and which Python is being used. When a non-None value is passed, it will be prepended to the default.

    - redirect (int/bool) – Controls the maximum number of redirections that can be followed by a request. Either an integer for a specific count or True/False for forever/never. (optional, default to 30)

    - additional_headers (dict) – Additional headers that should be attached to every request passing through the session. Headers of the same name specified per request will take priority.

    - app_name (str) – The name of the application that is creating the session. This will be used to create the user_agent.

    - app_version (str) – The version of the application creating the session. This will be used to create the user_agent.

    - additional_user_agent (list) – A list of tuple of name, version that will be added to the user agent. This can be used by libraries that are part of the communication process.

    - discovery_cache (dict) – A dict to be used for caching of discovery information. This is normally managed transparently, but if the user wants to share a single cache across multiple sessions that do not share an auth plugin, it can be provided here. (optional, defaults to None which means automatically manage)

    - split_loggers (bool) – Split the logging of requests across multiple loggers instead of just one. Defaults to False.

    - collect_timing (bool) – Whether or not to collect per-method timing information for each API call. (optional, defaults to False)

    - rate_semaphore – Semaphore to be used to control concurrency and rate limiting of requests. (optional, defaults to no concurrency or rate control)

    - connect_retries (int) – the maximum number of retries that should be attempted for connection errors. (optional, defaults to 0 - never retry).

  _DEFAULT_REDIRECT_LIMIT = 30
  _REDIRECT_STATUSES = (301, 302, 303, 305, 307, 308)
  __annotations_cache__ = {'_api_times': 'list[RequestTiming]', '_determined_user_agent': 'str | None', '_session': 'requests.Session | None'}
  __del__() → None

    Clean up resources on delete.

  __dict__ = mappingproxy({'__module__': 'keystoneauth1.session', '__firstlineno__': 288, '__doc__': "Maintains client communication state and common functionality.\n\nAs much as possible the parameters to this class reflect and are passed\ndirectly to the :mod:`requests` library.\n\n:param auth: An authentication plugin to authenticate the session with.\n (optional, defaults to None)\n:type auth: keystoneauth1.plugin.BaseAuthPlugin\n:param requests.Session session: A requests session object that can be used\n for issuing requests. (optional)\n:param str original_ip: The original IP of the requesting user which will\n be sent to identity service in a 'Forwarded'\n header. (optional)\n:param verify: The verification arguments to pass to requests. These are of\n the same form as requests expects, so True or False to\n verify (or not) against system certificates or a path to a\n bundle or CA certs to check against or None for requests to\n attempt to locate and use certificates. (optional, defaults\n to True)\n:param cert: A client certificate to pass to requests. These are of the\n same form as requests expects. Either a single filename\n containing both the certificate and key or a tuple containing\n the path to the certificate then a path to the key. (optional)\n:param float timeout: A timeout to pass to requests. This should be a\n numerical value indicating some amount (or fraction)\n of seconds or 0 for no timeout. (optional, defaults\n to 0)\n:param str user_agent: A User-Agent header string to use for the request.\n If not provided, a default of\n :attr:`~keystoneauth1.session.DEFAULT_USER_AGENT` is\n used, which contains the keystoneauth1 version as\n well as those of the requests library and which\n Python is being used. When a non-None value is\n passed, it will be prepended to the default.\n:param int/bool redirect: Controls the maximum number of redirections that\n can be followed by a request. Either an integer\n for a specific count or True/False for\n forever/never. (optional, default to 30)\n:param dict additional_headers: Additional headers that should be attached\n to every request passing through the\n session. Headers of the same name specified\n per request will take priority.\n:param str app_name: The name of the application that is creating the\n session. This will be used to create the user_agent.\n:param str app_version: The version of the application creating the\n session. This will be used to create the\n user_agent.\n:param list additional_user_agent: A list of tuple of name, version that\n will be added to the user agent. This\n can be used by libraries that are part\n of the communication process.\n:param dict discovery_cache: A dict to be used for caching of discovery\n information. This is normally managed\n transparently, but if the user wants to\n share a single cache across multiple sessions\n that do not share an auth plugin, it can\n be provided here. (optional, defaults to\n None which means automatically manage)\n:param bool split_loggers: Split the logging of requests across multiple\n loggers instead of just one. Defaults to False.\n:param bool collect_timing: Whether or not to collect per-method timing\n information for each API call. (optional,\n defaults to False)\n:param rate_semaphore: Semaphore to be used to control concurrency\n and rate limiting of requests. (optional,\n defaults to no concurrency or rate control)\n:param int connect_retries: the maximum number of retries that should\n be attempted for connection errors.\n (optional, defaults to 0 - never retry).\n", 'user_agent': None, '_REDIRECT_STATUSES': (301, 302, 303, 305, 307, 308), '_DEFAULT_REDIRECT_LIMIT': 30, '__init__': <function Session.__init__>, '__del__': <function Session.__del__>, 'adapters': <property object>, 'mount': <function Session.mount>, '_remove_service_catalog': <function Session._remove_service_catalog>, '_process_header': <staticmethod(<function Session._process_header>)>, '_get_split_loggers': <function Session._get_split_loggers>, '_http_log_request': <function Session._http_log_request>, '_http_log_response': <function Session._http_log_response>, '_set_microversion_headers': <staticmethod(<function Session._set_microversion_headers>)>, 'request': <function Session.request>, '_send_request': <function Session._send_request>, 'get': <function Session.get>, 'head': <function Session.head>, 'post': <function Session.post>, 'put': <function Session.put>, 'patch': <function Session.patch>, 'delete': <function Session.delete>, '_auth_required': <function Session._auth_required>, 'get_auth_headers': <function Session.get_auth_headers>, 'get_token': <function Session.get_token>, 'get_endpoint': <function Session.get_endpoint>, 'get_endpoint_data': <function Session.get_endpoint_data>, 'get_api_major_version': <function Session.get_api_major_version>, 'get_all_version_data': <function Session.get_all_version_data>, 'get_auth_connection_params': <function Session.get_auth_connection_params>, 'invalidate': <function Session.invalidate>, 'get_user_id': <function Session.get_user_id>, 'get_project_id': <function Session.get_project_id>, 'get_timings': <function Session.get_timings>, 'reset_timings': <function Session.reset_timings>, '__static_attributes__': ('_api_times', '_collect_timing', '_connect_retries', '_determined_user_agent', '_discovery_cache', '_json', '_rate_semaphore', '_session', '_split_loggers', 'additional_headers', 'additional_user_agent', 'app_name', 'app_version', 'auth', 'cert', 'original_ip', 'redirect', 'session', 'timeout', 'user_agent', 'verify'), '__dict__': <attribute '__dict__' of 'Session' objects>, '__weakref__': <attribute '__weakref__' of 'Session' objects>, '__annotations_cache__': {'_session': 'requests.Session | None', '_determined_user_agent': 'str | None', '_api_times': 'list[RequestTiming]'}})
  __doc__ = "Maintains client communication state and common functionality.\n\nAs much as possible the parameters to this class reflect and are passed\ndirectly to the :mod:`requests` library.\n\n:param auth: An authentication plugin to authenticate the session with.\n (optional, defaults to None)\n:type auth: keystoneauth1.plugin.BaseAuthPlugin\n:param requests.Session session: A requests session object that can be used\n for issuing requests. (optional)\n:param str original_ip: The original IP of the requesting user which will\n be sent to identity service in a 'Forwarded'\n header. (optional)\n:param verify: The verification arguments to pass to requests. These are of\n the same form as requests expects, so True or False to\n verify (or not) against system certificates or a path to a\n bundle or CA certs to check against or None for requests to\n attempt to locate and use certificates. (optional, defaults\n to True)\n:param cert: A client certificate to pass to requests. These are of the\n same form as requests expects. Either a single filename\n containing both the certificate and key or a tuple containing\n the path to the certificate then a path to the key. (optional)\n:param float timeout: A timeout to pass to requests. This should be a\n numerical value indicating some amount (or fraction)\n of seconds or 0 for no timeout. (optional, defaults\n to 0)\n:param str user_agent: A User-Agent header string to use for the request.\n If not provided, a default of\n :attr:`~keystoneauth1.session.DEFAULT_USER_AGENT` is\n used, which contains the keystoneauth1 version as\n well as those of the requests library and which\n Python is being used. When a non-None value is\n passed, it will be prepended to the default.\n:param int/bool redirect: Controls the maximum number of redirections that\n can be followed by a request. Either an integer\n for a specific count or True/False for\n forever/never. (optional, default to 30)\n:param dict additional_headers: Additional headers that should be attached\n to every request passing through the\n session. Headers of the same name specified\n per request will take priority.\n:param str app_name: The name of the application that is creating the\n session. This will be used to create the user_agent.\n:param str app_version: The version of the application creating the\n session. This will be used to create the\n user_agent.\n:param list additional_user_agent: A list of tuple of name, version that\n will be added to the user agent. This\n can be used by libraries that are part\n of the communication process.\n:param dict discovery_cache: A dict to be used for caching of discovery\n information. This is normally managed\n transparently, but if the user wants to\n share a single cache across multiple sessions\n that do not share an auth plugin, it can\n be provided here. (optional, defaults to\n None which means automatically manage)\n:param bool split_loggers: Split the logging of requests across multiple\n loggers instead of just one. Defaults to False.\n:param bool collect_timing: Whether or not to collect per-method timing\n information for each API call. (optional,\n defaults to False)\n:param rate_semaphore: Semaphore to be used to control concurrency\n and rate limiting of requests. (optional,\n defaults to no concurrency or rate control)\n:param int connect_retries: the maximum number of retries that should\n be attempted for connection errors.\n (optional, defaults to 0 - never retry).\n"
  __firstlineno__ = 288
  __init__(auth: plugin.BaseAuthPlugin | None = None, session: Session | None = None, original_ip: str | None = None, verify: bool | str | None = True, cert: str | tuple[str, str] | None = None, timeout: float | int | None = None, user_agent: str | None = None, redirect: int | bool = 30, additional_headers: MutableMapping[str, str] | None = None, app_name: str | None = None, app_version: str | None = None, additional_user_agent: list[tuple[str, str]] | None = None, discovery_cache: dict[str, Any] | None = None, split_loggers: bool | None = None, collect_timing: bool = False, rate_semaphore: ContextManager[None, bool | None] | None = None, connect_retries: int = 0)
  __module__ = 'keystoneauth1.session'
  __static_attributes__ = ('_api_times', '_collect_timing', '_connect_retries', '_determined_user_agent', '_discovery_cache', '_json', '_rate_semaphore', '_session', '_split_loggers', 'additional_headers', 'additional_user_agent', 'app_name', 'app_version', 'auth', 'cert', 'original_ip', 'redirect', 'session', 'timeout', 'user_agent', 'verify')
  __weakref__

    list of weak references to the object

  _api_times: list[RequestTiming]
  _auth_required(auth: plugin.BaseAuthPlugin | None, msg: str) → plugin.BaseAuthPlugin
  _determined_user_agent: str | None
  _get_split_loggers(split_loggers: bool | None) → bool | None

    Get a boolean value from the various argument sources.

    We default split_loggers to None in the kwargs of the Session constructor so we can track set vs. not set. We also accept split_loggers as a parameter in a few other places. In each place we want the parameter, if given by the user, to win.

  _http_log_request(url: str, method: str | None = None, data: str | bytes | None = None, json: object = None, headers: MutableMapping[str, str] | None = None, query_params: dict[str, Any] | None = None, logger: Logger | None = None, split_loggers: bool | None = None) → None
  _http_log_response(response: Response | None = None, json: object = None, status_code: int | None = None, headers: MutableMapping[str, str] | None = None, text: str | None = None, *, logger: Logger, split_loggers: bool | None = None) → None
  static _process_header(header: tuple[str, str]) → tuple[str, str]

    Redact the secure headers to be logged.

  _remove_service_catalog(body: str) → str
  _send_request(url: str, method: str, redirect: int | bool, log: bool, logger: Logger, split_loggers: bool | None, connect_retries: int, status_code_retries: int, retriable_status_codes: list[int], rate_semaphore: ContextManager[None, bool | None], connect_retry_delays: _Retries, status_code_retry_delays: _Retries, **kwargs: Any) → Response
  _session: Session | None
  static _set_microversion_headers(headers: MutableMapping[str, str], microversion: str, service_type: str | None, endpoint_filter: dict[str, Any] | None) → None
  property adapters: MutableMapping[Any, Any]
  delete(url: str, **kwargs: Any) → Response

    Perform a DELETE request.

    This calls `request()` with `method` set to `DELETE`.

  get(url: str, **kwargs: Any) → Response

    Perform a GET request.

    This calls `request()` with `method` set to `GET`.

  get_all_version_data(auth: plugin.BaseAuthPlugin | None = None, interface: str | list[str] | None = 'public', region_name: str | None = None, service_type: str | None = None) → dict[str, dict[str, dict[str, list[VersionData]]]]

    Get version data for all services in the catalog.

    Parameters:

      - auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

      - interface – Type of endpoint to get version data for. Can be a single value or a list of values. A value of None indicates that all interfaces should be queried. (optional, defaults to public)

      - region_name (string) – Region of endpoints to get version data for. A valueof None indicates that all regions should be queried. (optional, defaults to None)

      - service_type (string) – Limit the version data to a single service. (optional, defaults to None)

    Returns:

      A dictionary keyed by region_name with values containing dictionaries keyed by interface with values being a list of ~keystoneauth1.discover.VersionData.

  get_api_major_version(auth: plugin.BaseAuthPlugin | None = None, **kwargs: Any) → tuple[int | float, ...] | None

    Get the major API version as provided by the auth plugin.

    Parameters:

      auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

    Raises:

      keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – if a plugin is not available.

    Returns:

      The major version of the API of the service discovered.

    Return type:

      tuple or None

  get_auth_connection_params(auth: plugin.BaseAuthPlugin | None = None) → plugin.ConnectionParams

    Return auth connection params as provided by the auth plugin.

    An auth plugin may specify connection parameters to the request like providing a client certificate for communication.

    We restrict the values that may be returned from this function to prevent an auth plugin overriding values unrelated to connection parameters. The values that are currently accepted are:

    - cert: a path to a client certificate, or tuple of client certificate and key pair that are used with this request.

    - verify: a boolean value to indicate verifying SSL certificates against the system CAs or a path to a CA file to verify with.

    These values are passed to the requests library and further information on accepted values may be found there.

    Parameters:

      auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for tokens. Overrides the plugin on the session. (optional)

    Raises:

      - keystoneauth1.exceptions.auth.AuthorizationFailure – if a new token fetch fails.

      - keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – if a plugin is not available.

      - keystoneauth1.exceptions.auth_plugins.UnsupportedParameters – if the plugin returns a parameter that is not supported by this session.

    Returns:

      Authentication headers or None for failure.

    Return type:

      `dict`

  get_auth_headers(auth: plugin.BaseAuthPlugin | None = None) → dict[str, str] | None

    Return auth headers as provided by the auth plugin.

    Parameters:

      auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

    Raises:

      - keystoneauth1.exceptions.auth.AuthorizationFailure – if a new token fetch fails.

      - keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – if a plugin is not available.

    Returns:

      Authentication headers or None for failure.

    Return type:

      `dict`

  get_endpoint(auth: plugin.BaseAuthPlugin | None = None, *, endpoint_override: str | None = None, **kwargs: Any) → str | None

    Get an endpoint as provided by the auth plugin.

    Parameters:

      auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

    Raises:

      keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – if a plugin is not available.

    Returns:

      An endpoint if available or None.

    Return type:

      string

  get_endpoint_data(auth: plugin.BaseAuthPlugin | None = None, **kwargs: Any) → EndpointData | None

    Get endpoint data as provided by the auth plugin.

    Parameters:

      auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

    Raises:

      - keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – if a plugin is not available.

      - TypeError – If arguments are invalid

    Returns:

      Endpoint data if available or None.

    Return type:

      keystoneauth1.discover.EndpointData

  get_project_id(auth: plugin.BaseAuthPlugin | None = None) → str | None

    Return the authenticated project_id as provided by the auth plugin.

    Parameters:

      auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

    Raises:

      - keystoneauth1.exceptions.auth.AuthorizationFailure – if a new token fetch fails.

      - keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – if a plugin is not available.

    Returns:

      Current project_id or None if not supported by plugin.

    Return type:

      `str`

  get_timings() → list[RequestTiming]

    Return collected API timing information.

    Returns:

      List of RequestTiming objects.

  get_token(auth: plugin.BaseAuthPlugin | None = None) → str | None

    Return a token as provided by the auth plugin.

    Parameters:

      auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

    Raises:

      - keystoneauth1.exceptions.auth.AuthorizationFailure – if a new token fetch fails.

      - keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – if a plugin is not available.

    Warning

    DEPRECATED: This assumes that the only header that is used to authenticate a message is `X-Auth-Token`. This may not be correct. Use `get_auth_headers()` instead.

    Returns:

      A valid token.

    Return type:

      string

  get_user_id(auth: plugin.BaseAuthPlugin | None = None) → str | None

    Return the authenticated user_id as provided by the auth plugin.

    Parameters:

      auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use for token. Overrides the plugin on the session. (optional)

    Raises:

      - keystoneauth1.exceptions.auth.AuthorizationFailure – if a new token fetch fails.

      - keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – if a plugin is not available.

    Returns:

      Current user_id or None if not supported by plugin.

    Return type:

      `str`

  head(url: str, **kwargs: Any) → Response

    Perform a HEAD request.

    This calls `request()` with `method` set to `HEAD`.

  invalidate(auth: plugin.BaseAuthPlugin | None = None) → bool

    Invalidate an authentication plugin.

    Parameters:

      auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to invalidate. Overrides the plugin on the session. (optional)

  mount(scheme: str, adapter: BaseAdapter) → None
  patch(url: str, **kwargs: Any) → Response

    Perform a PATCH request.

    This calls `request()` with `method` set to `PATCH`.

  post(url: str, **kwargs: Any) → Response

    Perform a POST request.

    This calls `request()` with `method` set to `POST`.

  put(url: str, **kwargs: Any) → Response

    Perform a PUT request.

    This calls `request()` with `method` set to `PUT`.

  request(url: str, method: str, json: object | None = None, original_ip: str | None = None, user_agent: str | None = None, redirect: int | bool | None = None, authenticated: bool | None = None, endpoint_filter: dict[str, Any] | None = None, auth: plugin.BaseAuthPlugin | None = None, requests_auth: requests.auth.AuthBase | None = None, raise_exc: bool = True, allow_reauth: bool = True, log: bool = True, endpoint_override: str | None = None, connect_retries: int | None = None, logger: Logger | None = None, allow: dict[str, Any] | None = None, client_name: str | None = None, client_version: str | None = None, microversion: str | None = None, microversion_service_type: str | None = None, status_code_retries: int = 0, retriable_status_codes: list[int] | None = None, rate_semaphore: ContextManager[None, bool | None] | None = None, global_request_id: str | None = None, connect_retry_delay: float | None = None, status_code_retry_delay: float | None = None, **kwargs: Any) → Response

    Send an HTTP request with the specified characteristics.

    Wrapper around requests.Session.request to handle tasks such as setting headers, JSON encoding/decoding, and error handling.

    Arguments that are not handled are passed through to the requests library.

    Parameters:

      - url (str) – Path or fully qualified URL of HTTP request. If only a path is provided then endpoint_filter must also be provided such that the base URL can be determined. If a fully qualified URL is provided then endpoint_filter will be ignored.

      - method (str) – The http method to use. (e.g. ‘GET’, ‘POST’)

      - json – Some data to be represented as JSON. (optional)

      - original_ip (str) – Mark this request as forwarded for this ip. (optional)

      - headers (dict) – Headers to be included in the request. (optional)

      - user_agent (str) – A user_agent to use for the request. If present will override one present in headers. (optional)

      - redirect (int/bool) – the maximum number of redirections that can be followed by a request. Either an integer for a specific count or True/False for forever/never. (optional)

      - connect_retries (int) – the maximum number of retries that should be attempted for connection errors. (optional, defaults to None - never retry).

      - authenticated (bool) – True if a token should be attached to this request, False if not or None for attach if an auth_plugin is available. (optional, defaults to None)

      - endpoint_filter (dict) – Data to be provided to an auth plugin with which it should be able to determine an endpoint to use for this request. If not provided then URL is expected to be a fully qualified URL. (optional)

      - endpoint_override (str) – The URL to use instead of looking up the endpoint in the auth plugin. This will be ignored if a fully qualified URL is provided but take priority over an endpoint_filter. This string may contain the values `%(project_id)s` and `%(user_id)s` to have those values replaced by the project_id/user_id of the current authentication. (optional)

      - auth (keystoneauth1.plugin.BaseAuthPlugin) – The auth plugin to use when authenticating this request. This will override the plugin that is attached to the session (if any). (optional)

      - requests_auth (`requests.auth.AuthBase`) – A requests library auth plugin that cannot be passed via kwarg because the auth kwarg collides with our own auth plugins. (optional)

      - raise_exc (bool) – If True then raise an appropriate exception for failed HTTP requests. If False then return the request object. (optional, default True)

      - allow_reauth (bool) – Allow fetching a new token and retrying the request on receiving a 401 Unauthorized response. (optional, default True)

      - log (bool) – If True then log the request and response data to the debug log. (optional, default True)

      - logger (logging.Logger) – The logger object to use to log request and responses. If not provided the keystoneauth1.session default logger will be used.

      - allow (dict) – Extra filters to pass when discovering API versions. (optional)

      - microversion – Microversion to send for this request. microversion can be given as a string or a tuple. (optional)

      - microversion_service_type (str) – The service_type to be sent in the microversion header, if a microversion is given. Defaults to the value of service_type from endpoint_filter if one exists. If endpoint_filter is not provided or does not have a service_type, microversion is given and microversion_service_type is not provided, an exception will be raised.

      - status_code_retries (int) – the maximum number of retries that should be attempted for retriable HTTP status codes (optional, defaults to 0 - never retry).

      - retriable_status_codes (list) – list of HTTP status codes that should be retried (optional, defaults to HTTP 503, has no effect when status_code_retries is 0).

      - rate_semaphore – Semaphore to be used to control concurrency and rate limiting of requests. (optional, defaults to no concurrency or rate control)

      - global_request_id – Value for the X-Openstack-Request-Id header.

      - connect_retry_delay (float) – Delay (in seconds) between two connect retries (if enabled). By default exponential retry starting with 0.5 seconds up to a maximum of 60 seconds is used.

      - status_code_retry_delay (float) – Delay (in seconds) between two status code retries (if enabled). By default exponential retry starting with 0.5 seconds up to a maximum of 60 seconds is used.

      - kwargs –

        any other parameter that can be passed to `requests.Session.request()` (such as headers). Except:

        - data will be overwritten by the data in the json param.

        - allow_redirects is ignored as redirects are handled by the session.

    Raises:

      keystoneauth1.exceptions.base.ClientException – For connection failure, or to indicate an error response code.

    Returns:

      The response to the request.

  reset_timings() → None

    Clear API timing information.

  user_agent = None

class keystoneauth1.session.TCPKeepAliveAdapter(pool_connections: int = 10, pool_maxsize: int = 10, max_retries: int | Retry = 0, pool_block: bool = False)

  Bases: `HTTPAdapter`

  The custom adapter used to set TCP Keep-Alive on all connections.

  This Adapter also preserves the default behaviour of Requests which disables Nagle’s Algorithm. See also: https://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/25/nagle-s-algorithm-is-not-friendly-towards-small-requests.aspx

  __annotations_cache__ = {}
  __doc__ = "The custom adapter used to set TCP Keep-Alive on all connections.\n\nThis Adapter also preserves the default behaviour of Requests which\ndisables Nagle's Algorithm. See also:\nhttps://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/25/nagle-s-algorithm-is-not-friendly-towards-small-requests.aspx\n"
  __firstlineno__ = 1627
  __module__ = 'keystoneauth1.session'
  __static_attributes__ = ()
  init_poolmanager(*args: Any, **kwargs: Any) → None

    Initializes a urllib3 PoolManager.

    This method should not be called from user code, and is only exposed for use when subclassing the `HTTPAdapter`.

    Parameters:

      - connections – The number of urllib3 connection pools to cache.

      - maxsize – The maximum number of connections to save in the pool.

      - block – Block when no free connections are available.

      - pool_kwargs – Extra keyword arguments used to initialize the Pool Manager.

class keystoneauth1.session._JSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

  Bases: `JSONEncoder`

  __annotate_func__ = None
  __annotations_cache__ = {}
  __doc__ = None
  __firstlineno__ = 131
  __module__ = 'keystoneauth1.session'
  __static_attributes__ = ()
  default(o: object) → Any

    Implement this method in a subclass such that it returns a serializable object for `o`, or calls the base implementation (to raise a `TypeError`).

    For example, to support arbitrary iterators, you could implement default like this:

        def default(self, o):
            try:
                iterable = iter(o)
            except TypeError:
                pass
            else:
                return list(iterable)
            # Let the base class default method raise the TypeError
            return super().default(o)

class keystoneauth1.session._Retries(fixed_delay: float | None = None)

  Bases: `object`

  __annotations_cache__ = {'_current': <class 'float'>, '_fixed_delay': float | None}
  __doc__ = None
  __firstlineno__ = 266
  __init__(fixed_delay: float | None = None)
  __module__ = 'keystoneauth1.session'
  __next__() → float
  __slots__ = ('_fixed_delay', '_current')
  __static_attributes__ = ('_current', '_fixed_delay')
  _current: float
  _fixed_delay: float | None
  reset() → None

class keystoneauth1.session._StringFormatter(session: Session, auth: plugin.BaseAuthPlugin | None)

  Bases: `object`

  A String formatter that fetches values on demand.

  __annotate_func__ = None
  __annotations_cache__ = {}
  __dict__ = mappingproxy({'__module__': 'keystoneauth1.session', '__firstlineno__': 143, '__doc__': 'A String formatter that fetches values on demand.', '__init__': <function _StringFormatter.__init__>, '__getitem__': <function _StringFormatter.__getitem__>, '__static_attributes__': ('auth', 'session'), '__dict__': <attribute '__dict__' of '_StringFormatter' objects>, '__weakref__': <attribute '__weakref__' of '_StringFormatter' objects>, '__annotate_func__': None, '__annotations_cache__': {}})
  __doc__ = 'A String formatter that fetches values on demand.'
  __firstlineno__ = 143
  __getitem__(item: str) → Any
  __init__(session: Session, auth: plugin.BaseAuthPlugin | None)
  __module__ = 'keystoneauth1.session'
  __static_attributes__ = ('auth', 'session')
  __weakref__

    list of weak references to the object

keystoneauth1.session._construct_session(session_obj: Session | None = None) → Session

keystoneauth1.session._determine_calling_package() → str

  Walk the call frames trying to identify what is using this module.

keystoneauth1.session._determine_user_agent() → str

  Attempt to programmatically generate a user agent string.

  First, look at the name of the process. Return this unless it is in the ignored list. Otherwise, look at the function call stack and try to find the name of the code that invoked this module.

keystoneauth1.session._mv_legacy_headers_for_service(mv_service_type: str) → list[str]

  Workaround for services that predate standardization.

  TODO(sdague): eventually convert this to using os-service-types and put the logic there. However, right now this is so little logic, inlining it for release is a better call.

keystoneauth1.session._sanitize_headers(headers: dict[str | bytes, Any]) → dict[str, Any]

  Ensure headers are strings and not bytes.

this page last updated: 2026-07-14 15:48:40

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug