Base HTTP Client
psengine.base_http_client.BaseHTTPClient
¶
BaseHTTPClient(
http_proxy: str = None,
https_proxy: str = None,
verify: Union[str, bool] = SSL_VERIFY,
auth: tuple[str, str] = None,
cert: Union[str, tuple[str, str], None] = None,
timeout: int = REQUEST_TIMEOUT,
retries: int = RETRY_TOTAL,
backoff_factor: int = BACKOFF_FACTOR,
status_forcelist: int = STATUS_FORCELIST,
pool_max_size: int = POOL_MAX_SIZE,
)
Generic HTTP client for making requests (requests wrapper).
PARAMETER | DESCRIPTION |
---|---|
http_proxy
|
An HTTP proxy URL.
TYPE:
|
https_proxy
|
An HTTPS proxy URL.
TYPE:
|
verify
|
An SSL verification flag or path to CA bundle.
TYPE:
|
auth
|
Basic Auth credentials.
TYPE:
|
cert
|
Client certificates.
TYPE:
|
timeout
|
A request timeout.
TYPE:
|
retries
|
A number of retries.
TYPE:
|
backoff_factor
|
A backoff factor.
TYPE:
|
status_forcelist
|
A list of status codes to force a retry. Defaults to [502, 503, 504].
TYPE:
|
pool_max_size
|
The maximum number of connections in the pool.
TYPE:
|
Source code in psengine/base_http_client.py
backoff_factor
instance-attribute
¶
http_proxy
instance-attribute
¶
https_proxy
instance-attribute
¶
pool_max_size
instance-attribute
¶
status_forcelist
instance-attribute
¶
status_forcelist = (
status_forcelist
if status_forcelist is not None
else client_status_forcelist
)
call
¶
call(
method: str,
url: str,
data: Union[dict, list[dict], None] = None,
*,
params: Union[dict, None] = None,
headers: Union[dict, None] = None,
**kwargs,
) -> Response
Invoke an HTTP request using the requests
library.
PARAMETER | DESCRIPTION |
---|---|
method
|
An HTTP method.
TYPE:
|
url
|
A URL to make the request to.
TYPE:
|
data
|
A request body.
TYPE:
|
params
|
HTTP query parameters.
TYPE:
|
headers
|
If specified, overrides default headers and does not set the token.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If method is not one of GET, PUT, POST, DELETE, HEAD, OPTIONS, PATCH. |
HTTPError
|
If the response status is not 2xx. |
JSONDecodeError
|
If the response contains malformed JSON. |
ConnectTimeout
|
If the connection to the server times out. |
ConnectionError
|
If the request fails before completing. |
ReadTimeout
|
If the server did not send any data in time. |
RETURNS | DESCRIPTION |
---|---|
Response
|
A requests.Response object. |
Source code in psengine/base_http_client.py
can_connect
¶
Check if the client can reach the specified API URL.
PARAMETER | DESCRIPTION |
---|---|
method
|
An HTTP method.
TYPE:
|
url
|
A URL to test.recordedfuture.com.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if connection returns status 200, else False. |
Source code in psengine/base_http_client.py
set_urllib_log_level
¶
Set log level for urllib3 library.
PARAMETER | DESCRIPTION |
---|---|
level
|
A log level to be set: CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET.
TYPE:
|