From a3a942141dd2b0d81b5b27a180ef5af080ec00ac Mon Sep 17 00:00:00 2001 From: Karan Vaidya Date: Sat, 3 Aug 2024 18:13:48 +0530 Subject: [PATCH] Handle empty attachment (#415) --- python/composio/client/collections.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/python/composio/client/collections.py b/python/composio/client/collections.py index 280f6266211..fc20ceb22b2 100644 --- a/python/composio/client/collections.py +++ b/python/composio/client/collections.py @@ -1010,15 +1010,20 @@ def execute( modified_params[param] = base64.b64encode(file_content).decode( "utf-8" ) - elif file_uploadable and isinstance(value, str) and os.path.isfile(value): - with open(value, "rb") as file: - file_content = file.read() - encoded_data = base64.b64encode(file_content).decode("utf-8") - encoded_data_with_filename = { - "name": os.path.basename(value), - "content": encoded_data, - } - modified_params[param] = encoded_data_with_filename + elif file_uploadable and isinstance(value, str): + if os.path.isfile(value): + with open(value, "rb") as file: + file_content = file.read() + encoded_data = base64.b64encode(file_content).decode("utf-8") + encoded_data_with_filename = { + "name": os.path.basename(value), + "content": encoded_data, + } + modified_params[param] = encoded_data_with_filename + elif value == "": + pass + else: + return {"error": f"File with path {value} not found"} else: modified_params[param] = value