From a8abe5ff92bfee5f3737ab46e196a5bded876c41 Mon Sep 17 00:00:00 2001 From: Victor Verhaert <33786515+VictorVerhaert@users.noreply.github.com> Date: Fri, 19 Jan 2024 13:21:57 +0100 Subject: [PATCH] added parameter auto_decode to Connection.execute() github issue #499 --- openeo/rest/connection.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/openeo/rest/connection.py b/openeo/rest/connection.py index 4535c26a5..cf1a4a77e 100644 --- a/openeo/rest/connection.py +++ b/openeo/rest/connection.py @@ -1576,6 +1576,7 @@ def execute( process_graph: Union[dict, str, Path], timeout: Optional[int] = None, validate: Optional[bool] = None, + auto_decode: bool = True, ): """ Execute a process graph synchronously and return the result. If the result is a JSON object, it will be parsed. @@ -1584,6 +1585,7 @@ def execute( or as local file path or URL :param validate: Optional toggle to enable/prevent validation of the process graphs before execution (overruling the connection's ``auto_validate`` setting). + :param auto_decode: Boolean flag to enable/disable automatic JSON decoding of the response. Defaults to True. :return: if possible parsed JSON response, otherwise raw response """ @@ -1595,9 +1597,13 @@ def execute( expected_status=200, timeout=timeout or DEFAULT_TIMEOUT_SYNCHRONOUS_EXECUTE, ) - try: - return response.json() - except requests.exceptions.JSONDecodeError: + if auto_decode: + try: + return response.json() + except requests.exceptions.JSONDecodeError: + _log.warning("Failed to decode response as JSON, returning raw response.") + return response + else: return response def create_job(