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
__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
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: Union[str, int]

log level for this class kwargs=log_level

LOG: logging.Logger

Logger for this object.

url: str

URL to connect to

SAVE_LAST: bool

save requests to LAST_REQUEST and responses to LAST_RESPONSE kwargs=save_last

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

Headers to hide when logging.

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

HTTP proxy to use. kwargs=http_proxy

HTTPS_PROXY: Optional[str]

HTTPS proxy to use. kwargs=https_proxy

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

LOG_LEVEL_URLLIB: str

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

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

Type

requests.PreparedRequest

LAST_RESPONSE

last response received

Type

requests.Response

HISTORY

all responses received.

Type

list of requests.Response

session: requests.Session

session object to use

Type

requests.Session

__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 to url

  • route (typing.Optional[str]) – route to append to url

  • method (str) – HTTP method to use

  • data (typing.Optional[str]) – body to send

  • params (typing.Optional[dict]) – parameters to url encode

  • headers (typing.Optional[dict]) – headers to send

  • json (typing.Optional[dict]) – obj to encode as json

  • files (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

requests.Response

__str__()[source]

Show object info.

Return type

str

__repr__()[source]

Show object info.

Return type

str

property user_agent

Value to use in User-Agent header.

Return type

str

_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

Get the request attributes that should be logged.

Return type

typing.List[str]

property log_response_attrs

Get the response attributes that should be logged.

Return type

typing.List[str]

_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)[source]

Log a request or response body.

Parameters
  • body (str) – content to log

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