Python SDK

Errors

The exceptions the Python SDK raises, what each carries, and when.

Every exception the SDK raises derives from scute.ScuteError, except ValueError for bad arguments.

from scute import APIError, ConfigurationError, ConnectionError, InvalidToken, ScuteError

scute.ConnectionError is the SDK's own class and shadows Python's built-in ConnectionError when imported by name. Import it as from scute import ConnectionError as ScuteConnectionError if you need both.

Hierarchy#

ClassBaseRaised when
ScuteErrorExceptionBase for all of the below.
APIErrorScuteErrorScute answered with a status outside 2xx.
ConnectionErrorScuteErrorScute could not be reached, after one retry for idempotent calls.
ConfigurationErrorScuteErrorNo app id at construction, no secret for a secret-key call, or no credentials for a call.
InvalidTokenScuteErrorAn access token is not a live session of this app.

APIError#

AttributeTypeValue
str(e)strThe API's error, else its say, else Scute answered <status>
statusint or NoneHTTP status
codestr or NoneThe API's error_code, for example already_merged
bodyAnyThe decoded JSON body, or None
try:    scute.users.merge(user_id, old_id)except APIError as e:    if e.status == 422 and e.code == "already_merged":        ...    else:        raise

See the API reference for status codes and error codes.

InvalidToken#

Raised by scute.tokens.verify. e.reason is one of missing, malformed, algorithm, signature, expired, wrong_app, not_a_user, revoked. See Verify tokens.

try:    session = scute.tokens.verify(token)except InvalidToken as e:    return {"error": str(e), "reason": e.reason}, 401

verify can also raise ConnectionError or APIError when it cannot read the app's keys, or when remote=True and Scute answers with a status other than 401, 403 or 404. Treat those as "could not check", not as an invalid token.

ConfigurationError#

MessageCause
Scute needs an app id: pass app_id or set SCUTE_APP_IDScute() with no app id.
This call needs the app's secret key: pass secret or set SCUTE_SECRETA secret-key call on a client without a secret.
Harness needs agent: the agent's slug in ScuteHarness(agent="").

ValueError#

  • client_ip (constructor, with_client_ip, request) is not one IPv4 or IPv6 address.
  • authz.check_batch got more than 100 checks.

Framework responses#

The FastAPI and Flask helpers turn errors into responses:

CaseStatusBody
InvalidToken401error, reason
Decision is not a plain allow403error, decision

In FastAPI the body is under detail. APIError and ConnectionError from the check are not caught; they reach your app's error handling.