Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ try:
],
)
except PreparedDomainError as err:
# e.g. 409 in_progress, 429 out_of_allowance, 503 overloaded
# e.g. 409 in_progress, 429 out_of_allowance or domain_rejection_limit, 503 overloaded
print(err.status_code, err.code, err.detail)
raise

Expand All @@ -268,7 +268,9 @@ print(status["status"]) # "ready" or "failed" (see status["failure"])

`prepare_domain_async()` and `prepared_domain_status_async()` are the async counterparts. The client's `retries` setting doesn't apply to these calls, and an empty `domain` raises `ValueError` before any request.

Both methods raise `PreparedDomainError` on an error answer, with `status_code`, `code` (`invalid_argument`, `not_found`, `in_progress`, `out_of_allowance`, `overloaded`, `disabled`, ...), `detail`, `reason` and the whole `problem` body. See the [Extract endpoints docs](https://docs.zenrows.com/extract/endpoints?utm_source=github&utm_medium=readme&utm_campaign=zenrows-python-sdk) for every status and failure code.
Both methods raise `PreparedDomainError` on an error answer, with `status_code`, `code` (`invalid_argument`, `not_found`, `in_progress`, `out_of_allowance`, `domain_rejection_limit`, `overloaded`, `disabled`, ...), `detail`, `reason` and the whole `problem` body.

Two `429` codes mean different things. `out_of_allowance` means the account has no preparations left this month. `domain_rejection_limit` means this domain's preparations failed verification as many times as the monthly limit allows: don't submit this domain again this month, though other domains can still be prepared, and the refused submission cost nothing. Its `problem` also carries `domain`, `rejected`, `limit` and `month`. See the [Extract endpoints docs](https://docs.zenrows.com/extract/endpoints?utm_source=github&utm_medium=readme&utm_campaign=zenrows-python-sdk) for every status and failure code.

A `422` with `code: "no_data_extracted"` means Extract knows this kind of page but found no data on it. It isn't charged, and the client never retries it, even with `retries` set. `is_no_data_extracted(response)` tells you when you got one. See the [Extract docs](https://docs.zenrows.com/extract/setup?utm_source=github&utm_medium=readme&utm_campaign=zenrows-python-sdk).

Expand Down
14 changes: 9 additions & 5 deletions src/zenrows/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _check_domain(domain: str) -> None:
def _prepared_domains_request(method: str, url: str, **kwargs: Any) -> requests.Response:
# Not through `requests_session`: its retry adapter would retry a 429 or
# 503, which these endpoints use for answers to read (out_of_allowance,
# overloaded). The Go and Node SDKs skip client retries here too.
# domain_rejection_limit, overloaded). The Go and Node SDKs skip client retries here too.
with requests.Session() as session:
return session.request(method, url, **kwargs)

Expand All @@ -186,9 +186,13 @@ class PreparedDomainError(Exception):
`code` is the problem's `code` member, for example `invalid_argument`
(400), `not_found` (404), `in_progress` (409: a preparation is already
running, read its status instead of resubmitting), `out_of_allowance`
(429: no preparations left this month), or `overloaded` / `disabled`
(503); None when the body has no code. `problem` holds the whole body,
or None when it was not JSON.
(429: no preparations left this month), `domain_rejection_limit` (429:
this domain's preparations were rejected as many times as this month
allows; don't retry it this month, other domains still work), or
`overloaded` / `disabled` (503); None when the body has no code.
`problem` holds the whole body, or None when it was not JSON; a
`domain_rejection_limit` body also carries `domain`, `rejected`,
`limit` and `month`.
"""

def __init__(
Expand Down Expand Up @@ -439,7 +443,7 @@ def prepare_domain(self, domain: str, example_urls: list[str]) -> dict:
Raises `ValueError` for an empty `domain`, before any request, and
`PreparedDomainError` on a non-2xx answer, for example 400
`invalid_argument`, 409 `in_progress`, 429 `out_of_allowance` or
503 `overloaded` / `disabled`.
`domain_rejection_limit`, or 503 `overloaded` / `disabled`.
"""
_check_domain(domain)
response = _prepared_domains_request(
Expand Down
34 changes: 34 additions & 0 deletions tests/test_prepared_domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,40 @@ def test_prepare_429_is_not_retried(self):
self.assertEqual(caught.exception.code, "out_of_allowance")
self.assertEqual(len(self.api.requests), 1)

def test_prepare_429_domain_rejection_limit_is_not_retried(self):
detail = (
"www.example.com had 3 rejected preparation attempts this month (failed "
"verification); the limit is 3 per domain per month. This submission was not "
"accepted and not counted against your allowance. New attempts for this domain "
"reopen at the start of next month (UTC)."
)
problem = {
"type": "https://docs.zenrows.com/api-error-codes#domain_rejection_limit",
"title": "Domain rejection limit reached",
"status": 429,
"code": "domain_rejection_limit",
"detail": detail,
"domain": "www.example.com",
"rejected": 3,
"limit": 3,
"month": "2026-11",
}
self.api.reply(429, problem)
self.api.reply(202, PREPARING)

with self.assertRaises(PreparedDomainError) as caught:
self.client.prepare_domain("www.example.com", ["https://www.example.com/"])

err = caught.exception
self.assertEqual(err.status_code, 429)
self.assertEqual(err.code, "domain_rejection_limit")
self.assertEqual(err.detail, detail)
self.assertEqual(err.problem["domain"], "www.example.com")
self.assertEqual(err.problem["rejected"], 3)
self.assertEqual(err.problem["limit"], 3)
self.assertEqual(err.problem["month"], "2026-11")
self.assertEqual(len(self.api.requests), 1)

def test_scraping_keeps_its_retries(self):
"""Control: the same client still retries a 503 on a scraping request."""
self.api.reply(503, b"busy")
Expand Down
Loading