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
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
Raises

HttpError

  • 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.

url: str

URL to connect to

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 to LAST_RESPONSE kwargs=save_last

SAVE_HISTORY: bool

Append all responses to HISTORY kwargs=save_history

CONNECT_TIMEOUT: int

seconds to wait for connections to open to url kwargs=connect_timeout

RESPONSE_TIMEOUT: int

seconds to wait for responses from url kwargs=response_timeout

LOG_REQUEST_BODY: bool

Log the full request body kwargs=log_request_body

LOG_RESPONSE_BODY: bool

Log the full response body. kwargs=log_response_body

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

LOG_LEVEL_URLLIB: str

logging level for low-level urllib library. kwargs=log_level_urllib

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

Type

requests.PreparedRequest

LAST_RESPONSE

last response received

Type

requests.Response

HISTORY

all responses received.

Type

list of requests.Response

get_cert()[source]

Pass.

Return type

axonius_api_client.cert_human.stores.cert.Cert

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

axonius_api_client.parsers.url_parser.UrlParser

new_session()[source]

Pass.

set_session_headers()[source]

Pass.

set_session_cookies()[source]

Pass.

set_session_proxies()[source]

Pass.

set_session_verify()[source]

Pass.

set_session_cert()[source]

Pass.

set_urllib_warnings()[source]

Pass.

set_urllib_log()[source]

Pass.

__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
Returns

requests.Response

__str__()[source]

Show object info.

Return type

str

__repr__()[source]

Show object info.

Return type

str

property user_agent: str

Value to use in User-Agent header.

_do_log_request(request)[source]

Log attributes and/or body of a request.

Parameters

request (requests.PreparedRequest) – prepared request to log attrs/body of

_clean_headers(headers)[source]

Clean headers with sensitive information.

Parameters

headers (dict) – headers to clean values of

Return type

dict

_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: List[str]

Get the request attributes that should be logged.

property log_response_attrs: List[str]

Get the response attributes that should be logged.

_get_log_attrs(attr_type)[source]

Get the log attributes for a specific type.

Parameters

attr_type (str) – ‘request’ or ‘response’

Return type

typing.List[str]

_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 strings

  • attr_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 log

  • body_type (str) – ‘request’ or ‘response’

Return type

str

_init()[source]

Pass.