diff options
author | Chris Patterson <cpatterson@microsoft.com> | 2022-03-14 17:16:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 16:16:17 -0500 |
commit | 54bc8d24952e5e4d9771d296e0da2da97adb98ed (patch) | |
tree | 9625420c71a41c3c8304cdcee43358f841c3fc16 /cloudinit/url_helper.py | |
parent | dd60d788c98eb0a27b7dff4bc2f6c45db5b5c03d (diff) | |
download | cloud-init-git-54bc8d24952e5e4d9771d296e0da2da97adb98ed.tar.gz |
url_helper: add tuple support for readurl timeout (#1328)
It may be useful to configure connection timeout and read timeout
separately. Update readurl() to accept a tuple that is supported
by python requests to configure both.
Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
Diffstat (limited to 'cloudinit/url_helper.py')
-rw-r--r-- | cloudinit/url_helper.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py index c577e8da..b827eba9 100644 --- a/cloudinit/url_helper.py +++ b/cloudinit/url_helper.py @@ -194,7 +194,8 @@ def readurl( :param url: Mandatory url to request. :param data: Optional form data to post the URL. Will set request_method to 'POST' if present. - :param timeout: Timeout in seconds to wait for a response + :param timeout: Timeout in seconds to wait for a response. May be a tuple + if specifying (connection timeout, read timeout). :param retries: Number of times to retry on exception if exception_cb is None or exception_cb returns True for the exception caught. Default is to fail with 0 retries on exception. @@ -229,7 +230,10 @@ def readurl( request_method = "POST" if data else "GET" req_args["method"] = request_method if timeout is not None: - req_args["timeout"] = max(float(timeout), 0) + if isinstance(timeout, tuple): + req_args["timeout"] = timeout + else: + req_args["timeout"] = max(float(timeout), 0) if headers_redact is None: headers_redact = [] manual_tries = 1 |