From 0e89cf30a610bda8780c7f405b564ff0a83f47c2 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Wed, 18 Dec 2024 06:18:23 -0500 Subject: [PATCH] remove data encoding to json This commit removes the logic to encode the payload before sending the request. This library should not attempt to infer the data type and simply add the data to the request exactly as it was passed to the function. It is the responsibility of the upstream function to call the function with the appropriately encoded data. This commit will now check if the value of data is type of bytes and raise an exception if it is not --- plugins/module_utils/http.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/http.py b/plugins/module_utils/http.py index 5282e31..da7acf0 100644 --- a/plugins/module_utils/http.py +++ b/plugins/module_utils/http.py @@ -73,8 +73,10 @@ def send_request(method, url, headers=None, data=None, params=None, auth=None, t if certificate_file is not None and private_key_file is not None: kwargs["cert"] = (certificate_file, private_key_file) - if isinstance(kwargs.get("data"), (dict, list)) and kwargs.get("data"): - kwargs["data"] = json.dumps(data) + if data is not None: + if not isinstance(data, bytes): + raise AnsibleError(f"invalid type for data, expected bytes, got {type(data)}") + kwargs["data"] = data display.vvvvv(f"Request object: {kwargs}")