InsionInsion
Python

Errors

Handle Python API errors and access raw responses

Overview

This guide explains how to handle errors returned by the Insion SDK and inspect response details when troubleshooting failed requests.

Handle errors

Non-success responses raise ApiError; its status_code and body contain the API response. Transport and timeout failures retain their underlying exception.

from insion.core.api_error import ApiError

try:
    client.moderate_a_record(
        client_id="post-123", name="A post", entity="post", content="Hello",
    )
except ApiError as error:
    print(error.status_code, error.body)
    raise

Inspect raw responses

Use .with_raw_response when you need response metadata. It returns an object with data, headers, and status_code.

response = client.with_raw_response.list_records(limit=20)
print(response.status_code, response.headers, response.data.has_more)

The async client exposes the same property and errors; await its raw call.

How is this guide?

On this page

Latest Release

View the Python SDK on PyPIPython SDK versionPython SDK license