Exceptions¶
See Error Handling for usage guidance.
pycomptox.exceptions
¶
Exception hierarchy for PyCompTox.
All errors raised by PyCompTox clients derive from :class:CompToxError, so
callers can catch every library-specific failure with a single except
clause while still being able to distinguish the common cases.
Example
from pycomptox import Chemical from pycomptox.exceptions import NotFoundError, RateLimitError client = Chemical() try: ... details = client.search_by_exact_value("not-a-real-chemical") ... except NotFoundError: ... print("No such chemical") ... except RateLimitError as exc: ... print(f"Slow down; retry after {exc.retry_after}s")
APIError
¶
Bases: CompToxError
Raised when the CompTox API returns an unsuccessful HTTP response.
Attributes:
| Name | Type | Description |
|---|---|---|
status_code |
int
|
HTTP status code returned by the API. |
url |
str
|
The URL that was requested. |
response_text |
str
|
Raw response body, truncated. |
Source code in src/pycomptox/exceptions.py
AuthenticationError
¶
CompToxError
¶
ConfigurationError
¶
Bases: CompToxError
Raised when the client is misconfigured, e.g. no API key is available.
NotFoundError
¶
RateLimitError
¶
Bases: APIError
Raised on HTTP 429 - the API rate limit has been exceeded.
Attributes:
| Name | Type | Description |
|---|---|---|
retry_after |
float
|
Seconds to wait before retrying, taken
from the |
Source code in src/pycomptox/exceptions.py
ServerError
¶
TimeoutError
¶
Bases: CompToxError
Raised when a request exceeds the configured timeout.