madbot_cli.errors
Errors raised by the madbot client.
Every error of the package derives from MadbotError. An error of the API is
an ApiError, refined by the HTTP status of the answer, so that a caller can
catch NotFound without reading status codes.
The message of an ApiError is a sentence for a person: what madbot refused
and what to do next, without the URL or the JSON of the answer. raw() gives
the request and the answer, for --verbose; as_dict() gives them for
--json.
Attributes
| Name | Description |
|---|---|
BODY_EXCERPT | Longest part of an answer kept in the message of an error. |
CREDENTIAL_PARAMETERS | The parameters of a connection that carry its credentials, given by the environment. |
Classes
| Name | Description |
|---|---|
ApiError | A request to the madbot API failed. |
ApiUnreachable | The API gave no answer: wrong address, network down, or a timeout. |
Conflict | The object is not in a state that allows the request (HTTP 409). |
InvalidRequest | The API refused the request (HTTP 400): see code and details. |
MadbotError | Base class of the errors of the package. |
NotFound | The object does not exist, or the account cannot see it (HTTP 404). |
NotJson | The API answered something else than JSON, often the web application instead of the API. |
PermissionDenied | The account may not do this (HTTP 403). |
Redirected | The API sent the request to another address (HTTP 3xx), often https://. |
ServerError | The API failed (HTTP 500 or more). |
TaskFailed | A background task of madbot ended in failure. |
Unauthorized | The token is missing, unknown or expired (HTTP 401). |
WaitTimeout | Something madbot does in the background took longer than the client waits. |
BODY_EXCERPTattributemodule attribute#
BODY_EXCERPT = 2000Longest part of an answer kept in the message of an error.
CREDENTIAL_PARAMETERSattributemodule attribute#
CREDENTIAL_PARAMETERS = {'credentials', 'private_params'}The parameters of a connection that carry its credentials, given by the environment.
ApiErrorclass#
class ApiError(method: str, url: str, status: int | None, body: Any, message: str = '')Bases: MadbotError
A request to the madbot API failed.
Attributes
| Name | Type | Description |
|---|---|---|
method | str | The HTTP method of the request. |
url | str | The URL of the request. |
status | int or None | The HTTP status of the answer, None when the API gave no answer. |
body | Any | The answer, decoded from JSON when it is JSON, else its text. |
code | str or None | The code of a madbot error answer, such as body_validation_error. |
details | Any | The details of a madbot error answer: which parameter is wrong, and why. |
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
method | str | required | The HTTP method of the request. |
url | str | required | The URL of the request. |
status | int or None | required | The HTTP status of the answer, None when there was no answer. |
body | Any | required | The answer, or what went wrong. |
message | str | '' | A sentence for a person, put before the answer. |
bodyattributeinstance attribute#
body = bodycodeattributeinstance attribute#
code = body.get('code') if isinstance(body, dict) else Nonedetailsattributeinstance attribute#
details = body.get('details') if isinstance(body, dict) else Nonemessageattributeinstance attribute#
message = message or self.explain()methodattributeinstance attribute#
method = methodstatusattributeinstance attribute#
status = statusurlattributeinstance attribute#
url = urlas_dictmethod#
def as_dict() -> dictGive the request and the answer, as --json shows them.
Returns
dictmethod,url,statusand the decodedbody.
explainmethod#
def explain() -> strSay in a sentence what madbot answered, for an error built without a message.
Returns
str- What madbot refused, from the
detailsof its answer, without the URL or the JSON.
from_answermethodclassmethod#
def from_answer(method: str, url: str, status: int, body: Any) -> ApiErrorBuild the error that matches an HTTP status.
Parameters
Returns
ApiError- A
InvalidRequest,Unauthorized,PermissionDenied,NotFound,ConflictorServerError, or a plainApiErrorfor another status.
rawmethod#
def raw() -> strGive the request and the answer, as --verbose shows them.
Returns
strMETHOD URL -> HTTP status, then the answer (cut afterBODY_EXCERPTcharacters).
reasonmethod#
def reason() -> strSay why madbot refused, from its answer.
Returns
str- Each detail of the answer as
parameter: message, joined; themessageof the answer when it has no detail; empty when the answer is not a madbot error.
ApiUnreachableclass#
class ApiUnreachable(ApiError)Bases: ApiError
The API gave no answer: wrong address, network down, or a timeout.
attempts is how many times the request was sent: the client sends again
a request that can be repeated without effect.
aftermethod#
def after(attempts: int) -> ApiUnreachableSay the request was sent several times, in the message too.
Parameters
| Name | Type | Description |
|---|---|---|
attempts | int | How many times the request was sent. |
Returns
ApiUnreachable- The same error.
explainmethod#
def explain() -> strSay that madbot could not be reached, and where.
Returns
str- The host and the reason.
Inherited from madbot_cli.errors.ApiError
bodyattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcebody = bodycodeattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcecode = body.get('code') if isinstance(body, dict) else Nonedetailsattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcedetails = body.get('details') if isinstance(body, dict) else Nonemessageattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemessage = message or self.explain()methodattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemethod = methodstatusattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcestatus = statusurlattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourceurl = urlas_dictmethod#
madbot_cli.errors.ApiErrorView sourcedef as_dict() -> dictGive the request and the answer, as --json shows them.
Returns
dictmethod,url,statusand the decodedbody.
from_answermethodclassmethod#
madbot_cli.errors.ApiErrorView sourcedef from_answer(method: str, url: str, status: int, body: Any) -> ApiErrorBuild the error that matches an HTTP status.
Parameters
Returns
ApiError- A
InvalidRequest,Unauthorized,PermissionDenied,NotFound,ConflictorServerError, or a plainApiErrorfor another status.
rawmethod#
madbot_cli.errors.ApiErrorView sourcedef raw() -> strGive the request and the answer, as --verbose shows them.
Returns
strMETHOD URL -> HTTP status, then the answer (cut afterBODY_EXCERPTcharacters).
reasonmethod#
madbot_cli.errors.ApiErrorView sourcedef reason() -> strSay why madbot refused, from its answer.
Returns
str- Each detail of the answer as
parameter: message, joined; themessageof the answer when it has no detail; empty when the answer is not a madbot error.
Conflictclass#
class Conflict(ApiError)Bases: ApiError
The object is not in a state that allows the request (HTTP 409).
explainmethod#
def explain() -> strSay madbot cannot do it in the present state, and what to run.
Returns
str- Why, when madbot says it, and to run status.
Inherited from madbot_cli.errors.ApiError
bodyattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcebody = bodycodeattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcecode = body.get('code') if isinstance(body, dict) else Nonedetailsattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcedetails = body.get('details') if isinstance(body, dict) else Nonemessageattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemessage = message or self.explain()methodattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemethod = methodstatusattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcestatus = statusurlattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourceurl = urlas_dictmethod#
madbot_cli.errors.ApiErrorView sourcedef as_dict() -> dictGive the request and the answer, as --json shows them.
Returns
dictmethod,url,statusand the decodedbody.
from_answermethodclassmethod#
madbot_cli.errors.ApiErrorView sourcedef from_answer(method: str, url: str, status: int, body: Any) -> ApiErrorBuild the error that matches an HTTP status.
Parameters
Returns
ApiError- A
InvalidRequest,Unauthorized,PermissionDenied,NotFound,ConflictorServerError, or a plainApiErrorfor another status.
rawmethod#
madbot_cli.errors.ApiErrorView sourcedef raw() -> strGive the request and the answer, as --verbose shows them.
Returns
strMETHOD URL -> HTTP status, then the answer (cut afterBODY_EXCERPTcharacters).
reasonmethod#
madbot_cli.errors.ApiErrorView sourcedef reason() -> strSay why madbot refused, from its answer.
Returns
str- Each detail of the answer as
parameter: message, joined; themessageof the answer when it has no detail; empty when the answer is not a madbot error.
InvalidRequestclass#
class InvalidRequest(ApiError)Bases: ApiError
The API refused the request (HTTP 400): see code and details.
explainmethod#
def explain() -> strSay which parameter madbot refused, and why.
Returns
str- The parameters refused, and to fix them in the file.
Inherited from madbot_cli.errors.ApiError
bodyattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcebody = bodycodeattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcecode = body.get('code') if isinstance(body, dict) else Nonedetailsattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcedetails = body.get('details') if isinstance(body, dict) else Nonemessageattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemessage = message or self.explain()methodattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemethod = methodstatusattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcestatus = statusurlattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourceurl = urlas_dictmethod#
madbot_cli.errors.ApiErrorView sourcedef as_dict() -> dictGive the request and the answer, as --json shows them.
Returns
dictmethod,url,statusand the decodedbody.
from_answermethodclassmethod#
madbot_cli.errors.ApiErrorView sourcedef from_answer(method: str, url: str, status: int, body: Any) -> ApiErrorBuild the error that matches an HTTP status.
Parameters
Returns
ApiError- A
InvalidRequest,Unauthorized,PermissionDenied,NotFound,ConflictorServerError, or a plainApiErrorfor another status.
rawmethod#
madbot_cli.errors.ApiErrorView sourcedef raw() -> strGive the request and the answer, as --verbose shows them.
Returns
strMETHOD URL -> HTTP status, then the answer (cut afterBODY_EXCERPTcharacters).
reasonmethod#
madbot_cli.errors.ApiErrorView sourcedef reason() -> strSay why madbot refused, from its answer.
Returns
str- Each detail of the answer as
parameter: message, joined; themessageof the answer when it has no detail; empty when the answer is not a madbot error.
MadbotErrorclass#
class MadbotError(Exception)Bases: Exception
Base class of the errors of the package.
NotFoundclass#
class NotFound(ApiError)Bases: ApiError
The object does not exist, or the account cannot see it (HTTP 404).
explainmethod#
def explain() -> strSay madbot does not find the object, and what to run.
Returns
str- Why it may be missing, and to run plan.
Inherited from madbot_cli.errors.ApiError
bodyattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcebody = bodycodeattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcecode = body.get('code') if isinstance(body, dict) else Nonedetailsattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcedetails = body.get('details') if isinstance(body, dict) else Nonemessageattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemessage = message or self.explain()methodattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemethod = methodstatusattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcestatus = statusurlattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourceurl = urlas_dictmethod#
madbot_cli.errors.ApiErrorView sourcedef as_dict() -> dictGive the request and the answer, as --json shows them.
Returns
dictmethod,url,statusand the decodedbody.
from_answermethodclassmethod#
madbot_cli.errors.ApiErrorView sourcedef from_answer(method: str, url: str, status: int, body: Any) -> ApiErrorBuild the error that matches an HTTP status.
Parameters
Returns
ApiError- A
InvalidRequest,Unauthorized,PermissionDenied,NotFound,ConflictorServerError, or a plainApiErrorfor another status.
rawmethod#
madbot_cli.errors.ApiErrorView sourcedef raw() -> strGive the request and the answer, as --verbose shows them.
Returns
strMETHOD URL -> HTTP status, then the answer (cut afterBODY_EXCERPTcharacters).
reasonmethod#
madbot_cli.errors.ApiErrorView sourcedef reason() -> strSay why madbot refused, from its answer.
Returns
str- Each detail of the answer as
parameter: message, joined; themessageof the answer when it has no detail; empty when the answer is not a madbot error.
NotJsonclass#
class NotJson(ApiError)Bases: ApiError
The API answered something else than JSON, often the web application instead of the API.
Inherited from madbot_cli.errors.ApiError
bodyattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcebody = bodycodeattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcecode = body.get('code') if isinstance(body, dict) else Nonedetailsattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcedetails = body.get('details') if isinstance(body, dict) else Nonemessageattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemessage = message or self.explain()methodattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemethod = methodstatusattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcestatus = statusurlattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourceurl = urlas_dictmethod#
madbot_cli.errors.ApiErrorView sourcedef as_dict() -> dictGive the request and the answer, as --json shows them.
Returns
dictmethod,url,statusand the decodedbody.
explainmethod#
madbot_cli.errors.ApiErrorView sourcedef explain() -> strSay in a sentence what madbot answered, for an error built without a message.
Returns
str- What madbot refused, from the
detailsof its answer, without the URL or the JSON.
from_answermethodclassmethod#
madbot_cli.errors.ApiErrorView sourcedef from_answer(method: str, url: str, status: int, body: Any) -> ApiErrorBuild the error that matches an HTTP status.
Parameters
Returns
ApiError- A
InvalidRequest,Unauthorized,PermissionDenied,NotFound,ConflictorServerError, or a plainApiErrorfor another status.
rawmethod#
madbot_cli.errors.ApiErrorView sourcedef raw() -> strGive the request and the answer, as --verbose shows them.
Returns
strMETHOD URL -> HTTP status, then the answer (cut afterBODY_EXCERPTcharacters).
reasonmethod#
madbot_cli.errors.ApiErrorView sourcedef reason() -> strSay why madbot refused, from its answer.
Returns
str- Each detail of the answer as
parameter: message, joined; themessageof the answer when it has no detail; empty when the answer is not a madbot error.
PermissionDeniedclass#
class PermissionDenied(ApiError)Bases: ApiError
The account may not do this (HTTP 403).
explainmethod#
def explain() -> strSay the account may not do it, and whom to ask.
Returns
str- Why, when madbot says it, and whom to ask.
Inherited from madbot_cli.errors.ApiError
bodyattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcebody = bodycodeattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcecode = body.get('code') if isinstance(body, dict) else Nonedetailsattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcedetails = body.get('details') if isinstance(body, dict) else Nonemessageattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemessage = message or self.explain()methodattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemethod = methodstatusattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcestatus = statusurlattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourceurl = urlas_dictmethod#
madbot_cli.errors.ApiErrorView sourcedef as_dict() -> dictGive the request and the answer, as --json shows them.
Returns
dictmethod,url,statusand the decodedbody.
from_answermethodclassmethod#
madbot_cli.errors.ApiErrorView sourcedef from_answer(method: str, url: str, status: int, body: Any) -> ApiErrorBuild the error that matches an HTTP status.
Parameters
Returns
ApiError- A
InvalidRequest,Unauthorized,PermissionDenied,NotFound,ConflictorServerError, or a plainApiErrorfor another status.
rawmethod#
madbot_cli.errors.ApiErrorView sourcedef raw() -> strGive the request and the answer, as --verbose shows them.
Returns
strMETHOD URL -> HTTP status, then the answer (cut afterBODY_EXCERPTcharacters).
reasonmethod#
madbot_cli.errors.ApiErrorView sourcedef reason() -> strSay why madbot refused, from its answer.
Returns
str- Each detail of the answer as
parameter: message, joined; themessageof the answer when it has no detail; empty when the answer is not a madbot error.
Redirectedclass#
class Redirected(ApiError)Bases: ApiError
The API sent the request to another address (HTTP 3xx), often https://.
The client does not follow: the token would go to the new address, and a
POST would come back as a GET. location is the address given, if any.
ofmethodclassmethod#
def of(method: str, url: str, status: int, location: str | None) -> RedirectedBuild the error, with the address to use instead.
Parameters
Returns
Redirected- The error.
Inherited from madbot_cli.errors.ApiError
bodyattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcebody = bodycodeattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcecode = body.get('code') if isinstance(body, dict) else Nonedetailsattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcedetails = body.get('details') if isinstance(body, dict) else Nonemessageattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemessage = message or self.explain()methodattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemethod = methodstatusattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcestatus = statusurlattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourceurl = urlas_dictmethod#
madbot_cli.errors.ApiErrorView sourcedef as_dict() -> dictGive the request and the answer, as --json shows them.
Returns
dictmethod,url,statusand the decodedbody.
explainmethod#
madbot_cli.errors.ApiErrorView sourcedef explain() -> strSay in a sentence what madbot answered, for an error built without a message.
Returns
str- What madbot refused, from the
detailsof its answer, without the URL or the JSON.
from_answermethodclassmethod#
madbot_cli.errors.ApiErrorView sourcedef from_answer(method: str, url: str, status: int, body: Any) -> ApiErrorBuild the error that matches an HTTP status.
Parameters
Returns
ApiError- A
InvalidRequest,Unauthorized,PermissionDenied,NotFound,ConflictorServerError, or a plainApiErrorfor another status.
rawmethod#
madbot_cli.errors.ApiErrorView sourcedef raw() -> strGive the request and the answer, as --verbose shows them.
Returns
strMETHOD URL -> HTTP status, then the answer (cut afterBODY_EXCERPTcharacters).
reasonmethod#
madbot_cli.errors.ApiErrorView sourcedef reason() -> strSay why madbot refused, from its answer.
Returns
str- Each detail of the answer as
parameter: message, joined; themessageof the answer when it has no detail; empty when the answer is not a madbot error.
ServerErrorclass#
class ServerError(ApiError)Bases: ApiError
The API failed (HTTP 500 or more).
explainmethod#
def explain() -> strSay madbot failed, and what to do.
Returns
str- The status, what madbot says, and to try again then tell the administrators.
Inherited from madbot_cli.errors.ApiError
bodyattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcebody = bodycodeattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcecode = body.get('code') if isinstance(body, dict) else Nonedetailsattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcedetails = body.get('details') if isinstance(body, dict) else Nonemessageattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemessage = message or self.explain()methodattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemethod = methodstatusattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcestatus = statusurlattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourceurl = urlas_dictmethod#
madbot_cli.errors.ApiErrorView sourcedef as_dict() -> dictGive the request and the answer, as --json shows them.
Returns
dictmethod,url,statusand the decodedbody.
from_answermethodclassmethod#
madbot_cli.errors.ApiErrorView sourcedef from_answer(method: str, url: str, status: int, body: Any) -> ApiErrorBuild the error that matches an HTTP status.
Parameters
Returns
ApiError- A
InvalidRequest,Unauthorized,PermissionDenied,NotFound,ConflictorServerError, or a plainApiErrorfor another status.
rawmethod#
madbot_cli.errors.ApiErrorView sourcedef raw() -> strGive the request and the answer, as --verbose shows them.
Returns
strMETHOD URL -> HTTP status, then the answer (cut afterBODY_EXCERPTcharacters).
reasonmethod#
madbot_cli.errors.ApiErrorView sourcedef reason() -> strSay why madbot refused, from its answer.
Returns
str- Each detail of the answer as
parameter: message, joined; themessageof the answer when it has no detail; empty when the answer is not a madbot error.
TaskFailedclass#
class TaskFailed(task: dict)Bases: MadbotError
A background task of madbot ended in failure.
Attributes
| Name | Type | Description |
|---|---|---|
task | dict | The task as the API returns it, with its status and result. |
Parameters
| Name | Type | Description |
|---|---|---|
task | dict | The task as the API returns it. |
Unauthorizedclass#
class Unauthorized(ApiError)Bases: ApiError
The token is missing, unknown or expired (HTTP 401).
explainmethod#
def explain() -> strSay the token is refused, and what token to give.
Returns
str- What to check.
Inherited from madbot_cli.errors.ApiError
bodyattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcebody = bodycodeattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcecode = body.get('code') if isinstance(body, dict) else Nonedetailsattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcedetails = body.get('details') if isinstance(body, dict) else Nonemessageattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemessage = message or self.explain()methodattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcemethod = methodstatusattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourcestatus = statusurlattributeinstance attribute#
madbot_cli.errors.ApiErrorView sourceurl = urlas_dictmethod#
madbot_cli.errors.ApiErrorView sourcedef as_dict() -> dictGive the request and the answer, as --json shows them.
Returns
dictmethod,url,statusand the decodedbody.
from_answermethodclassmethod#
madbot_cli.errors.ApiErrorView sourcedef from_answer(method: str, url: str, status: int, body: Any) -> ApiErrorBuild the error that matches an HTTP status.
Parameters
Returns
ApiError- A
InvalidRequest,Unauthorized,PermissionDenied,NotFound,ConflictorServerError, or a plainApiErrorfor another status.
rawmethod#
madbot_cli.errors.ApiErrorView sourcedef raw() -> strGive the request and the answer, as --verbose shows them.
Returns
strMETHOD URL -> HTTP status, then the answer (cut afterBODY_EXCERPTcharacters).
reasonmethod#
madbot_cli.errors.ApiErrorView sourcedef reason() -> strSay why madbot refused, from its answer.
Returns
str- Each detail of the answer as
parameter: message, joined; themessageof the answer when it has no detail; empty when the answer is not a madbot error.
WaitTimeoutclass#
class WaitTimeout(MadbotError)Bases: MadbotError
Something madbot does in the background took longer than the client waits.

