From 53934f30ef2852a329836d971aaa406d64c2c7f1 Mon Sep 17 00:00:00 2001 From: "linji.xue" Date: Fri, 10 Feb 2023 16:15:41 +0800 Subject: [PATCH] feat(utility): add "verify" attr to "requests.Config" --- docs/source/advanced_features/request_configuration.rst | 3 +++ tensorbay/utility/requests.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/source/advanced_features/request_configuration.rst b/docs/source/advanced_features/request_configuration.rst index 505689a41..5ffdb080f 100644 --- a/docs/source/advanced_features/request_configuration.rst +++ b/docs/source/advanced_features/request_configuration.rst @@ -30,6 +30,9 @@ Note that the default settings can satisfy most use cases. * - allowed_retry_status - | The allowed status for retrying request. | Default: [429, 500, 502, 503, 504] + * - verify + - | Whether to verify the server's TLS certificate. + | Default: True * - timeout - | The number of seconds before the request times out. | Scenario: Enlarge it when under poor network quality. diff --git a/tensorbay/utility/requests.py b/tensorbay/utility/requests.py index 382759e2a..7a1738617 100644 --- a/tensorbay/utility/requests.py +++ b/tensorbay/utility/requests.py @@ -46,6 +46,7 @@ class Config: allowed_retry_methods: The allowed methods for retrying request. allowed_retry_status: The allowed status for retrying request. If both methods and status are fitted, the retrying strategy will work. + verify: Whether to verify the server's TLS certificate. timeout: Timeout value of the request in seconds. is_internal: Whether the request is from internal. @@ -56,6 +57,7 @@ def __init__(self) -> None: self.max_retries = 3 self.allowed_retry_methods = ["HEAD", "OPTIONS", "POST", "PUT"] self.allowed_retry_status = [429, 500, 502, 503, 504] + self.verify = True self.timeout = 30 self.is_internal = False @@ -144,7 +146,7 @@ def request( # type: ignore[override] """ try: - response = super().request(method, url, *args, **kwargs) + response = super().request(method, url, *args, verify=config.verify, **kwargs) if response.status_code not in (200, 201): logger.error( "Unexpected status code(%d)!%s", response.status_code, ResponseLogging(response)