4.7.5.3. HTTP Client¶
HTTP client.
-
class
axonius_api_client.http.
Http
(url, certpath=None, certwarn=True, certverify=False, **kwargs)[source]¶ Bases:
object
HTTP client that wraps around around
requests.Session
.- Parameters
url (
typing.Union
[axonius_api_client.parsers.url_parser.UrlParser
,str
]) –certpath (
typing.Union
[str
,pathlib.Path
,None
]) –certwarn (
bool
) –certverify (
bool
) –
-
__init__
(url, certpath=None, certwarn=True, certverify=False, **kwargs)[source]¶ HTTP client that wraps around
requests.Session
.Notes
If certpath is supplied, certverify is ignored
private key supplied to cert_client_key or cert_client_both can NOT be password encrypted
- Parameters
url (
typing.Union
[axonius_api_client.parsers.url_parser.UrlParser
,str
]) – URL, hostname, or IP address of Axonius instancecertpath (
typing.Union
[str
,pathlib.Path
,None
]) – path to CA bundle file to use when verifying certs offered byurl
certverify (
bool
) – raise exception if cert is self-signed or only if cert is invalidcertwarn (
bool
) – show insecure warning once or never show insecure warningproxy – proxy to use when making https requests to
url
- Raises
if either cert_client_cert or cert_client_key are supplied, and the other is not supplied - if any of cert_path, cert_client_cert, cert_client_key, or cert_client_both are supplied and the file does not exist
-
LOG
: logging.Logger¶ Logger for this object.
-
SAVE_LAST
: bool¶ save requests to
LAST_REQUEST
and responses toLAST_RESPONSE
kwargs=save_last
-
LOG_REQUEST_ATTRS
: Optional[List[str]]¶ request attrs to log
axonius_api_client.constants.logs.REQUEST_ATTR_MAP
kwargs=log_request_attrs
-
LOG_RESPONSE_ATTRS
: Optional[List[str]]¶ response attrs to log
axonius_api_client.constants.logs.RESPONSE_ATTR_MAP
kwargs=log_response_attrs
-
CERT_CLIENT_KEY
: Optional[Union[str, pathlib.Path]]¶ Private key file for cert_client_cert
kwargs=cert_client_key
-
CERT_CLIENT_CERT
: Optional[Union[str, pathlib.Path]]¶ cert file to offer to
url
kwargs=cert_client_cert
-
CERT_CLIENT_BOTH
: Optional[Union[str, pathlib.Path]]¶ cert file with both private key and cert to offer to
url
kwargs=cert_client_both
-
LAST_REQUEST
¶ last request sent
-
LAST_RESPONSE
¶ last response received
- Type
-
HISTORY
¶ all responses received.
- Type
-
session
: requests.sessions.Session¶ session object to use
- Type
-
__call__
(path=None, route=None, method='get', data=None, params=None, headers=None, json=None, files=None, **kwargs)[source]¶ Create, prepare, and then send a request using
session
.- Parameters
path (
typing.Optional
[str
]) – path to append tourl
route (
typing.Optional
[str
]) – route to append tourl
method (
str
) – HTTP method to usedata (
typing.Optional
[str
]) – body to sendparams (
typing.Optional
[dict
]) – parameters to url encodeheaders (
typing.Optional
[dict
]) – headers to sendjson (
typing.Optional
[dict
]) – obj to encode as jsonfiles (
typing.Optional
[tuple
]) – files to send**kwargs –
overrides for object attributes
connect_timeout: seconds to wait for connection to open for this request
response_timeout: seconds to wait for for response for this request
proxies: proxies for this request
verify: verification of cert for this request
cert: client cert to offer for this request
- Returns
-
_do_log_request
(request)[source]¶ Log attributes and/or body of a request.
- Parameters
request (
requests.PreparedRequest
) – prepared request to log attrs/body of
-
_do_log_response
(response)[source]¶ Log attributes and/or body of a response.
- Parameters
response (
requests.Response
) – response to log attrs/body of
-
property
log_request_attrs
¶ Get the request attributes that should be logged.
- Return type
-
property
log_response_attrs
¶ Get the response attributes that should be logged.
- Return type
-
_get_log_attrs
(attr_type)[source]¶ Get the log attributes for a specific type.
- Parameters
attr_type (
str
) – ‘request’ or ‘response’- Return type
-
_set_log_attrs
(attr_map, attr_type, value)[source]¶ Set the log attributes for a specific type.
- Parameters
attr_map (
dict
) – map of attributes to format stringsattr_type (
str
) – ‘request’ or ‘response’value (
typing.Union
[str
,typing.List
[str
]]) – user supplied attrs to log