4.7.5.3. HTTP Client¶
HTTP client.
- class axonius_api_client.http.Http(url, certpath=None, certwarn=True, certverify=False, headers=None, cookies=None, **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
) –headers (
typing.Union
[dict
,requests.structures.CaseInsensitiveDict
,None
]) –cookies (
typing.Union
[dict
,requests.cookies.RequestsCookieJar
,None
]) –
- HIDE_STR = '*********'¶
- __init__(url, certpath=None, certwarn=True, certverify=False, headers=None, cookies=None, **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
headers (
typing.Union
[dict
,requests.structures.CaseInsensitiveDict
,None
]) –cookies (
typing.Union
[dict
,requests.cookies.RequestsCookieJar
,None
]) –
- 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_LEVEL:
typing.Union
[str
,int
]¶ log level for this class
kwargs=log_level
-
LOG:
logging.Logger
¶ Logger for this object.
-
LOG_HIDE_HEADERS:
typing.List
[typing.Union
[str
,typing.Pattern
]]¶ Headers to hide when logging.
-
SAVE_LAST:
bool
¶ save requests to
LAST_REQUEST
and responses toLAST_RESPONSE
kwargs=save_last
-
HTTP_PROXY:
typing.Optional
[str
]¶ HTTP proxy to use.
kwargs=http_proxy
-
HTTPS_PROXY:
typing.Optional
[str
]¶ HTTPS proxy to use.
kwargs=https_proxy
-
LOG_REQUEST_ATTRS:
typing.Optional
[typing.List
[str
]]¶ request attrs to log
axonius_api_client.constants.logs.REQUEST_ATTR_MAP
kwargs=log_request_attrs
-
LOG_RESPONSE_ATTRS:
typing.Optional
[typing.List
[str
]]¶ response attrs to log
axonius_api_client.constants.logs.RESPONSE_ATTR_MAP
kwargs=log_response_attrs
-
CERT_CLIENT_KEY:
typing.Union
[str
,pathlib.Path
,None
]¶ Private key file for cert_client_cert
kwargs=cert_client_key
-
CERT_CLIENT_CERT:
typing.Union
[str
,pathlib.Path
,None
]¶ cert file to offer to
url
kwargs=cert_client_cert
-
CERT_CLIENT_BOTH:
typing.Union
[str
,pathlib.Path
,None
]¶ 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
- get_cert_chain()[source]¶
Pass.
- Return type
typing.List
[axonius_api_client.cert_human.stores.cert.Cert
]
- parse_url(url)[source]¶
Pass.
- Parameters
url (
typing.Union
[str
,axonius_api_client.parsers.url_parser.UrlParser
]) –- Return type
- __call__(path=None, route=None, method='get', data=None, params=None, headers=None, cookies=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
cookies (
typing.Optional
[dict
]) –
- 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
- _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
- log_body(body, body_type, src=None)[source]¶
Get a string for logging a request or response body.
- Parameters
body (
typing.Any
) – content to logbody_type (
str
) – ‘request’ or ‘response’
- Return type