diff --git a/cirro/helpers/pyodide_patch_httpx.py b/cirro/helpers/pyodide_patch_httpx.py index 938dbfde..651ec198 100644 --- a/cirro/helpers/pyodide_patch_httpx.py +++ b/cirro/helpers/pyodide_patch_httpx.py @@ -38,8 +38,20 @@ def _send_single_request(self: Client, request: Request) -> Response: headers=request.headers, data=request.content, auth=auth_patched, + stream=True ) + # If the response is not successful, raise an HTTPError + if not resp.ok: + raise httpx.HTTPStatusError( + f"HTTP request failed with status code {resp.status_code}", + request=request, + response=resp + ) + + # Read the content of the response and decode it + content = resp.raw.read(decode_content=True) + # Remove content-encoding header to prevent httpx from trying to decode the content # since requests already decodes the content if "content-encoding" in resp.headers: @@ -49,7 +61,7 @@ def _send_single_request(self: Client, request: Request) -> Response: response = Response( status_code=resp.status_code, headers=Headers(resp.headers), - content=resp.content, + content=content, request=httpx.Request(method=resp.request.method, url=str(resp.url)), ) diff --git a/pyproject.toml b/pyproject.toml index c884f7f9..dce06faf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cirro" -version = "1.5.2" +version = "1.5.3" description = "CLI tool and SDK for interacting with the Cirro platform" authors = ["Cirro Bio "] license = "MIT"