Skip to content

Commit

Permalink
added parameter auto_decode to Connection.execute()
Browse files Browse the repository at this point in the history
github issue #499
  • Loading branch information
VictorVerhaert committed Jan 19, 2024
1 parent b6d6099 commit a8abe5f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions openeo/rest/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
"""
Expand All @@ -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(
Expand Down

0 comments on commit a8abe5f

Please sign in to comment.