Exceptions
exceptions
¶
Exception hierarchy and structured error envelope for the
Scrape.do Async API surface
Defines the typed exceptions raised by the ScrapeDoAsyncAPIClient,
AsyncScrapeDoAsyncAPIClient, and polling helpers. In addition, defines
AsyncScrapeDoErrorMessage, a
pydantic model wrapping the {Error, Code} JSON body returned by
q.scrape.do on non-2xx responses
AsyncScrapeDoErrorMessage
¶
Bases: BaseModel
Structured representation of a Scrape.do Async API error body
Tolerant Parsing
-
Server-side additions are silently ignored (
extra="ignore") -
Missing fields fall back to their defaults
Different From The Sync Envelope
-
The synchronous gateway's
ScrapeDoJSONErrorMessageuses a richer schema (StatusCode,Message,PossibleCauses,ErrorType, etc.) -
Errorcarries the human-readable description,Codecarries the HTTP status code -
Both models follow the same
try_from_responseparsing contract so callers can route either envelope to typed exceptions without special-casing
Attributes:
| Name | Type | Description |
|---|---|---|
error |
Optional[str]
|
human-readable description of what went wrong |
code |
Optional[int]
|
HTTP status code echoed in the body |
try_from_response(raw_resp)
classmethod
¶
Parse a Scrape.do Async API error envelope, or return None
Return Value
-
If
raw_resphas a parsable JSON body containing at least oneErrorandCodeAND thepydanticvalidation of this model succeeds, this method returns a validatedAsyncScrapeDoErrorMessageinstance -
Otherwise, it returns
None -
This method never raises
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_resp
|
Response
|
The raw |
required |
Returns:
| Type | Description |
|---|---|
Optional[AsyncScrapeDoErrorMessage]
|
An |
AsyncAPIError
¶
Bases: ScrapeDoError
Base exception for every error raised by the Scrape.do Async API
surface
Routing
-
Catching this class guarantees every Async-API-originated failure is handled
-
It inherits from
ScrapeDoError, so aexcept ScrapeDoErrorblock still catches it
AsyncAPIResponseError
¶
Bases: AsyncAPIError
Base for non-2xx HTTP responses returned by q.scrape.do
Error Parsing
-
Parses the response body via
AsyncScrapeDoErrorMessage.try_from_responseto populateself.message -
Falls back to an
Unknown API Errorrendering when the body isn't a recognizable Async API envelope
Attributes:
| Name | Type | Description |
|---|---|---|
raw_response |
Response
|
The raw |
raw_status_code |
int
|
The HTTP status code (shortcut for
|
error_info |
Optional[AsyncScrapeDoErrorMessage]
|
Parsed envelope
or |
AsyncAPIUnparsableResponseError
¶
Bases: AsyncAPIError
Raised when the SDK can't parse a successful response sent by
q.scrape.do
This can either happen because the response sent by q.scrape.do is not
parsable JSON, or because one of the endpoints returned an unexpected JSON
schema and caused one of the custom pydantic response models to raise a
ValidationError
Additional Exception Information
This exception is always chained to either a JSONDecodeError or a
ValidationError
exception to provide additional information on what caused the error
Attributes:
| Name | Type | Description |
|---|---|---|
raw_response |
Response
|
The raw |
AsyncAPIBadRequestError
¶
Bases: AsyncAPIResponseError
Raised when q.scrape.do returns HTTP 400
Indicates the job request was rejected at schema validation
Attributes:
| Name | Type | Description |
|---|---|---|
raw_response |
Response
|
The raw |
raw_status_code |
int
|
The HTTP status code (shortcut for
|
error_info |
Optional[AsyncScrapeDoErrorMessage]
|
Parsed envelope
or |
AsyncAPIAuthError
¶
Bases: AsyncAPIResponseError
Raised when q.scrape.do returns HTTP 401
Indicates the X-Token header is missing or invalid
Attributes:
| Name | Type | Description |
|---|---|---|
raw_response |
Response
|
The raw |
raw_status_code |
int
|
The HTTP status code (shortcut for
|
error_info |
Optional[AsyncScrapeDoErrorMessage]
|
Parsed envelope
or |
AsyncAPINotFoundError
¶
Bases: AsyncAPIResponseError
Raised when q.scrape.do returns HTTP 404
Indicates the requested JobID / TaskID does not exist or has
already expired
Attributes:
| Name | Type | Description |
|---|---|---|
raw_response |
Response
|
The raw |
raw_status_code |
int
|
The HTTP status code (shortcut for
|
error_info |
Optional[AsyncScrapeDoErrorMessage]
|
Parsed envelope
or |
AsyncAPINotAcceptableError
¶
Bases: AsyncAPIResponseError
Raised when q.scrape.do returns HTTP 406
Indicates the request is structurally valid but cannot be served in the current state (e.g. canceling a job that already completed)
Attributes:
| Name | Type | Description |
|---|---|---|
raw_response |
Response
|
The raw |
raw_status_code |
int
|
The HTTP status code (shortcut for
|
error_info |
Optional[AsyncScrapeDoErrorMessage]
|
Parsed envelope
or |
AsyncAPIRateLimitError
¶
Bases: AsyncAPIResponseError
Raised when q.scrape.do returns HTTP 429
Indicates the account has exhausted its Async-API concurrency
allowance (roughly 30% of the main plan concurrency)
Attributes:
| Name | Type | Description |
|---|---|---|
raw_response |
Response
|
The raw |
raw_status_code |
int
|
The HTTP status code (shortcut for
|
error_info |
Optional[AsyncScrapeDoErrorMessage]
|
Parsed envelope
or |
AsyncAPIServerError
¶
Bases: AsyncAPIResponseError
Raised when q.scrape.do returns a 5xx status code
Indicates a gateway or proxy pool failure on Scrape.do's side
Attributes:
| Name | Type | Description |
|---|---|---|
raw_response |
Response
|
The raw |
raw_status_code |
int
|
The HTTP status code (shortcut for
|
error_info |
Optional[AsyncScrapeDoErrorMessage]
|
Parsed envelope
or |
JobLifecycleError
¶
Bases: AsyncAPIError
Base for terminal-state errors surfaced by polling helpers
Raised by wait_for_job and submit_and_wait when the job reaches
a terminal status the caller didn't expect
Attributes:
| Name | Type | Description |
|---|---|---|
job |
JobDetails
|
The |
JobFailedError
¶
Bases: JobLifecycleError
Raised when a polled job reaches terminal status error
Attributes:
| Name | Type | Description |
|---|---|---|
job |
JobDetails
|
The |
Per-Task Errors
After the polling helper raises, callers can still inspect each
task's error_message via the corresponding
TaskDetails
JobCanceledError
¶
Bases: JobLifecycleError
Raised when a polled job reaches terminal status canceled
Attributes:
| Name | Type | Description |
|---|---|---|
job |
JobDetails
|
The |
TaskLifecycleError
¶
Bases: AsyncAPIError
Base for terminal-state errors surfaced by TaskDetails
Raised by TaskDetails.raise_for_status
when the task has reached a terminal failure status the caller
didn't expect
Includes the task.error_message in the exception's error message if it
exists.
Attributes:
| Name | Type | Description |
|---|---|---|
task |
TaskDetails
|
The |
TaskFailedError
¶
Bases: TaskLifecycleError
Raised when a TaskDetails snapshot has terminal status error
Attributes:
| Name | Type | Description |
|---|---|---|
task |
TaskDetails
|
The |
TaskCanceledError
¶
Bases: TaskLifecycleError
Raised when a TaskDetails snapshot has terminal status
canceled
Attributes:
| Name | Type | Description |
|---|---|---|
task |
TaskDetails
|
The |
JobTimeoutError
¶
Bases: AsyncAPIError
Raised when the PollingStrategy.__call__, or a user-defined
PollingFunction has chosen to stop polling for a job before it reached
a terminal status
Attributes:
| Name | Type | Description |
|---|---|---|
job_id |
str
|
The |
last_status |
str
|
The last non-terminal status observed before timing out |
elapsed |
float
|
Total seconds spent polling before timeout |
attempts |
int
|
Number of |