{"id":28711,"date":"2026-11-29T16:34:16","date_gmt":"2026-11-29T16:34:16","guid":{"rendered":"https:\/\/capskip.com\/?p=28711"},"modified":"2026-11-29T16:34:16","modified_gmt":"2026-11-29T16:34:16","slug":"tenacity-captcha-retry","status":"publish","type":"post","link":"https:\/\/capskip.com\/zh\/tenacity-captcha-retry\/","title":{"rendered":"Python \u4e2d\u7684 Tenacity \u9a8c\u8bc1\u7801\u91cd\u8bd5\uff1a\u4e24\u4e2a\u88c5\u9970\u5668\uff0c\u800c\u4e0d\u662f\u4e00\u4e2a"},"content":{"rendered":"<p>Tenacity captcha retry in Python takes two decorators, not one. Put the first on the call that fetches a token from the <a href=\"https:\/\/capskip.com\/python-captcha-solver\/\">CapSkip Python SDK<\/a> and the second on the form post that uses it. They fail for different reasons, and one decorator around both pays for a fresh solve whenever the site is merely busy. Below are the errors worth retrying, the budget traps and an async version, all measured against mocks.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">What you need before adding retries<\/h2>\n<ul>\n<li>Python 3.10 or newer, the minimum declared by capskip 1.8.0, tenacity 9.2.1 and requests 2.34.2. I ran Python 3.11.7, 3.13.7 and 3.14.0 on Windows 11, not 3.10. Run python -m pip install capskip tenacity requests to get all three.<\/li>\n<li>CapSkip on a Windows PC, plus the form address of the page you automate.<\/li>\n<li>Somewhere to reach CapSkip. Local mode keeps the API on 127.0.0.1, so only the same PC can call it. Server mode makes it listen on your network or public IP, which lets a script on a second machine call it. Find the switch in <a href=\"https:\/\/capskip.com\/setup-guide\/#connection-settings\">the connection settings section of the setup guide<\/a>.<\/li>\n<\/ul>\n<p>The CapSkip app did not answer on this PC, so I wrote two mock servers: a stand-in for CapSkip (in.php and res.php) and a stand-in for a contact form with a reCAPTCHA v2 widget. Every delay, failure and site rule below is my own mock rule, and the CapSkip error names come from the API docs, not from a real app. Numbers are Python 3.14.0, capskip 1.8.0 and tenacity 9.2.1 against the mock. My mock consumes a token only when it processes a form post, so a 429 or 503 leaves it usable. A real site may differ.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">Which CapSkip errors deserve a retry<\/h2>\n<p>The four exception classes derive from CapSkipError. The rows below come from the SDK source and the mock, not from the README.<\/p>\n<table>\n<thead>\n<tr>\n<th>Class<\/th>\n<th>Raised when<\/th>\n<th>Retry it?<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>ValidationException<\/td>\n<td>Raised on your PC before anything is sent, for example an unsupported option. The mock saw 0 tasks<\/td>\n<td>Never, the same call fails the same way<\/td>\n<\/tr>\n<tr>\n<td>ApiException with ERROR_CAPTCHA_UNSOLVABLE or ERROR_NO_SLOT_AVAILABLE<\/td>\n<td>A poll answer, or a full queue or request limit. The docs name both<\/td>\n<td>Yes, as a new task<\/td>\n<\/tr>\n<tr>\n<td>ApiException with any other code<\/td>\n<td>A wrong key, a missing page address or a missing sitekey. ERROR_KEY_DOES_NOT_EXIST and ERROR_PAGEURL each stopped after 1 task<\/td>\n<td>Never<\/td>\n<\/tr>\n<tr>\n<td>NetworkException<\/td>\n<td>Raised while submitting, when the connection fails or in.php answers anything but 200<\/td>\n<td>Yes, a few times<\/td>\n<\/tr>\n<tr>\n<td>TimeoutException<\/td>\n<td>The polling deadline passed<\/td>\n<td>Once or twice at most<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Three details shape the predicate. ApiException has no code attribute, so you match the message text. NetworkException can only come out of the submit step: during polling the SDK swallows it, because the same class also means &quot;not ready yet&quot;, so a res.php that answered HTTP 500 on every poll ended in TimeoutException after 3.76 seconds with recaptchaTimeout at 3. And a refused connection took 2.05 seconds to fail on Windows, so a dead app is slow to report.<\/p>\n<p>TimeoutException is the doubtful row. The SDK has no call to cancel a task, so the app may still be working on the abandoned one while your retry submits another. I could not check that against the real app, so keep the attempt count low.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">Build the script in four steps<\/h2>\n<h3 style=\"font-size:1.3rem;line-height:1.4;\">Step 1: set up the page and the solver<\/h3>\n<p>Save this block as retry_form.py and add every later block at the end, in order, up to Step 4, skipping naive_send if you like. To reach a CapSkip on another PC, replace 127.0.0.1 in host with that PC&#8217;s address. The sitekey comes from the data-sitekey attribute, so the script reads it instead of hard-coding it.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"python\" class=\"EnlighterJSRAW\"># python -m pip install capskip tenacity requests\nimport re\n\nimport requests\nfrom capskip import ApiException, CapSkip, NetworkException, TimeoutException\nfrom tenacity import (\n    retry,\n    retry_if_exception,\n    retry_if_exception_type,\n    stop_after_attempt,\n    stop_after_delay,\n    wait_random_exponential,\n)\n\nFORM_URL = &quot;https:\/\/example.com\/contact&quot;  # the page that shows the widget\nSUBMIT_URL = &quot;https:\/\/example.com\/contact\/send&quot;  # the form's action address\n\n# Local mode. In Server mode, use the address of the CapSkip machine.\nsolver = CapSkip(host=&quot;127.0.0.1&quot;, port=8080, recaptchaTimeout=60)\n\n\ndef open_form():\n    session = requests.Session()\n    page = session.get(FORM_URL, timeout=15)  # cookies arrive with the page\n    page.raise_for_status()\n    found = re.search(r'data-sitekey=[&quot;\\']([^&quot;\\']+)[&quot;\\']', page.text)\n    if not found:\n        raise RuntimeError(&quot;no data-sitekey on the page&quot;)\n    return session, found.group(1)<\/pre>\n<\/div>\n<h3 style=\"font-size:1.3rem;line-height:1.4;\">Step 2: the tenacity captcha retry for the solve<\/h3>\n<p>The solve gets one decorator. The retry argument joins two tests with a pipe: retry_if_exception_type for the classes that are transient, and retry_if_exception for the ApiException codes worth repeating. If you set replacement text for unsolvable tasks in CapSkip, match it too. ValidationException matches neither and surfaces on the first call. The wait is wait_random_exponential, which draws each sleep at random from a window that doubles up to the max, so several workers don&#8217;t retry in step.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">RETRY_CODES = (&quot;ERROR_CAPTCHA_UNSOLVABLE&quot;, &quot;ERROR_NO_SLOT_AVAILABLE&quot;)\n\n\ndef is_retryable(err):\n    # ApiException has no code attribute: the code is in the message text.\n    return isinstance(err, ApiException) and any(c in str(err) for c in RETRY_CODES)\n\n\ndef say_retry(state):\n    err = state.outcome.exception()\n    wait = state.next_action.sleep\n    print(f&quot;  attempt {state.attempt_number}: {type(err).__name__}, sleeping {wait:.1f}s&quot;)\n\n\n@retry(\n    retry=retry_if_exception_type((NetworkException, TimeoutException))\n    | retry_if_exception(is_retryable),  # ValidationException is not listed\n    stop=stop_after_attempt(3) | stop_after_delay(120),\n    wait=wait_random_exponential(multiplier=1, max=20),  # full jitter\n    before_sleep=say_retry,\n    reraise=True,  # raise the SDK error itself, not tenacity.RetryError\n)\ndef solve_token(sitekey):\n    # Every attempt is a NEW task: a result can be read only once.\n    return solver.recaptcha(sitekey, FORM_URL)[&quot;code&quot;]<\/pre>\n<\/div>\n<p>Without reraise=True, tenacity raises its own RetryError once the attempts run out, and a handler for the SDK classes never fires. With it, the original exception comes out: five unsolvable answers in a row ended in ApiException after 3 tasks. Every attempt is a new task, because a result can be read only once.<\/p>\n<h3 style=\"font-size:1.3rem;line-height:1.4;\">Step 3: retry the form post on its own<\/h3>\n<p>A form post fails differently. The site can answer 429 or 503, or reset the connection, and the token may still be good, so the right move is to send the same token again. The next block adds two exception classes and a wait function. A wait is any callable that takes the retry state and returns seconds. This one obeys Retry-After when the header holds a number, up to 30 seconds, and otherwise falls back to the jittered backoff. A Retry-After can also be an HTTP date, which this version sends to the fallback. The <a href=\"https:\/\/capskip.com\/http-429-too-many-requests\/\">guide to HTTP 429<\/a> parses the date form, and MDN documents <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Reference\/Headers\/Retry-After\" rel=\"noopener nofollow\" target=\"_blank\">the Retry-After header<\/a>.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">class RateLimited(Exception):\n    def __init__(self, seconds):\n        super().__init__(f&quot;429, Retry-After {seconds}&quot;)\n        self.seconds = seconds  # None when the header is missing or a date\n\n\nclass Busy(Exception):\n    pass\n\n\njitter = wait_random_exponential(multiplier=1, max=20)\n\n\ndef wait_for_form(state):\n    err = state.outcome.exception()\n    if isinstance(err, RateLimited) and err.seconds is not None:\n        return min(err.seconds, 30)  # obey Retry-After, up to a ceiling\n    return jitter(state)<\/pre>\n<\/div>\n<p>The function turns those answers into exceptions and leaves the rest alone. A 200 page that says the captcha check failed is a response, not an error, and Step 4 handles it.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">@retry(\n    retry=retry_if_exception_type(\n        (requests.ConnectionError, requests.Timeout, RateLimited, Busy)\n    ),\n    stop=stop_after_attempt(4),\n    wait=wait_for_form,\n    before_sleep=say_retry,\n    reraise=True,\n)\ndef post_form(session, token, name, message):\n    reply = session.post(\n        SUBMIT_URL,\n        data={&quot;name&quot;: name, &quot;message&quot;: message, &quot;g-recaptcha-response&quot;: token},\n        headers={&quot;Referer&quot;: FORM_URL},  # requests sends none by itself\n        timeout=15,\n    )\n    if reply.status_code == 429:\n        raw = reply.headers.get(&quot;Retry-After&quot;, &quot;&quot;)\n        raise RateLimited(int(raw) if raw.isdigit() else None)\n    if reply.status_code in (502, 503, 504):\n        raise Busy(f&quot;HTTP {reply.status_code}&quot;)\n    return reply<\/pre>\n<\/div>\n<p>Two 429 answers with Retry-After set to 2 produced waits of 2.0 and 2.0 seconds, 3 form posts and 1 solve. A 429, a 503 and a reset gave 4 form posts, 1 solve and a saved message. Six 503 answers stopped after 4 posts with Busy, still 1 solve. If a site processed a request and lost only the reply, the same token fails the second time, which costs one extra solve in Step 4.<\/p>\n<h3 style=\"font-size:1.3rem;line-height:1.4;\">Why one decorator around both costs solves<\/h3>\n<p>A decorated function re-runs everything inside it. The tempting version puts one decorator around a function that solves and then posts.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">from tenacity import wait_fixed\n\n\n@retry(\n    retry=retry_if_exception_type((NetworkException, TimeoutException, RateLimited, Busy)),\n    stop=stop_after_attempt(4),\n    wait=wait_fixed(1),\n    reraise=True,\n)\ndef naive_send(session, sitekey, name, message):\n    token = solver.recaptcha(sitekey, FORM_URL)[&quot;code&quot;]  # runs again on every retry\n    return post_form.__wrapped__(session, token, name, message)  # no inner retry<\/pre>\n<\/div>\n<p>It looks tidy and wastes solves. With the mock answering 503 twice, naive_send used 3 solves for 3 form posts, where the two decorators used 1 solve for the same 3 posts. Two 429 answers did the same. A solve takes seconds and a busy site takes none, so every blip becomes a full solve. Nesting is worse, because attempt limits multiply: an outer 4 attempts around the 4 of post_form sent 16 form posts and 4 solves against a mock that always answered 503, in 10 to 18 seconds across three runs.<\/p>\n<h3 style=\"font-size:1.3rem;line-height:1.4;\">Step 4: solve again only when the token is refused<\/h3>\n<p>One failure still needs a new solve: the site took the request and refused the token. That arrives as an ordinary page, so no decorator sees it, and a short loop handles it. Each round asks for a fresh token, because a token is single use. The refusal test is a whole phrase from your site, not the bare word captcha, which the widget markup may repeat. Replace the phrase and the success sign with the ones your site shows.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">def send_message(name, message, rounds=3):\n    session, sitekey = open_form()\n    for number in range(1, rounds + 1):\n        token = solve_token(sitekey)  # a fresh token for every round\n        reply = post_form(session, token, name, message)  # same token inside\n        if &quot;Message saved&quot; in reply.text:  # your site's success sign\n            return number\n        if &quot;captcha check failed&quot; not in reply.text.lower():  # your phrase\n            raise RuntimeError(f&quot;refused ({reply.status_code}), not the captcha&quot;)\n        print(f&quot;  round {number}: token refused, solving again&quot;)\n    raise RuntimeError(f&quot;token refused {rounds} times&quot;)\n\n\nif __name__ == &quot;__main__&quot;:\n    print(&quot;saved in round&quot;, send_message(&quot;alice&quot;, &quot;Hello&quot;))<\/pre>\n<\/div>\n<p>Run it with python retry_form.py. The tenacity captcha retry script ran as written here against the mock:<\/p>\n<table>\n<thead>\n<tr>\n<th>Mock setting<\/th>\n<th>Tasks<\/th>\n<th>Form posts<\/th>\n<th>Result<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Everything works<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<td>Saved in round 1<\/td>\n<\/tr>\n<tr>\n<td>Two ERROR_CAPTCHA_UNSOLVABLE answers, then a pass<\/td>\n<td>3<\/td>\n<td>1<\/td>\n<td>Saved<\/td>\n<\/tr>\n<tr>\n<td>ERROR_CAPTCHA_UNSOLVABLE five times<\/td>\n<td>3<\/td>\n<td>0<\/td>\n<td>ApiException<\/td>\n<\/tr>\n<tr>\n<td>ERROR_KEY_DOES_NOT_EXIST<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<td>ApiException at once<\/td>\n<\/tr>\n<tr>\n<td>An unsupported option<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>ValidationException at once<\/td>\n<\/tr>\n<tr>\n<td>in.php answers HTTP 500 twice<\/td>\n<td>3<\/td>\n<td>1<\/td>\n<td>Saved<\/td>\n<\/tr>\n<tr>\n<td>Nothing listens on the CapSkip port<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>NetworkException after 7.0 to 8.7 s<\/td>\n<\/tr>\n<tr>\n<td>ERROR_NO_SLOT_AVAILABLE once, then a pass<\/td>\n<td>2<\/td>\n<td>1<\/td>\n<td>Saved<\/td>\n<\/tr>\n<tr>\n<td>Site refuses the token once<\/td>\n<td>2<\/td>\n<td>2<\/td>\n<td>Saved in round 2<\/td>\n<\/tr>\n<tr>\n<td>Site refuses the token every time<\/td>\n<td>3<\/td>\n<td>3<\/td>\n<td>RuntimeError after 3 rounds<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">What stop_after_delay really bounds<\/h2>\n<p>The SDK has its own deadline, recaptchaTimeout (300 seconds by default for reCAPTCHA), and tenacity has stop_after_delay. Neither is a wall clock. The SDK checks its deadline only between polls, which back off from 0.25 seconds toward pollingInterval, so the failure lands late: with a mock that never answered, recaptchaTimeout of 3 raised after 3.76 seconds, 10 after 12.77 and 20 after 22.77. A pass ready after 2 seconds arrived at 3.77.<\/p>\n<p>Tenacity checks stop_after_delay after an attempt ends, never during one. With recaptchaTimeout at 3, stop_after_delay(5) and a fixed 0.5 second wait, the second attempt began at about 4.3 seconds, inside the budget, and the run ended at about 8. The stop_before_delay variant ended at the same time, because it counts the coming sleep, not the length of the attempt. With recaptchaTimeout at 1 the same budget ended at about 6.3. Size the SDK timeout first and read the tenacity budget as a rough ceiling.<\/p>\n<p>The sync client has a harder problem: the SDK calls requests without a timeout, so a server that accepts in.php and never replies blocks the call for good. Mine was still blocked after 15 seconds, when I stopped it, and no tenacity setting interrupts a running call.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">AsyncRetrying with AsyncCapSkip<\/h2>\n<p>AsyncCapSkip is a real async client built on httpx, and AsyncRetrying sleeps with asyncio, not time.sleep. Many retrying jobs can run at once, and each attempt can get a hard limit from asyncio.wait_for, which tenacity cannot do itself. Against a mock that never answered, a 2 second wait_for with 3 attempts and a fixed 0.5 second wait started them at 0, 2.5 and 5.0 seconds and ended at 7.0, with the SDK timeout left at 60. The mock kept all three abandoned tasks and the real app may too, so keep the limit generous.<\/p>\n<p>The async client also times out by itself. httpx waits 5 seconds by default, so the silent server that blocked the sync client raised NetworkException after about 5.3 seconds, which the retry treats as transient. Save the next block as retry_async.py beside retry_form.py. One retry object serves every call: 1,200 calls through one shared AsyncRetrying, 60 at a time, each ran the expected number of attempts in a tenacity-only test on Python 3.14.0.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">import asyncio\n\nfrom capskip import AsyncCapSkip, NetworkException, TimeoutException\nfrom tenacity import (\n    AsyncRetrying,\n    retry_if_exception,\n    retry_if_exception_type,\n    stop_after_attempt,\n    stop_after_delay,\n    wait_random_exponential,\n)\n\nfrom retry_form import FORM_URL, is_retryable, open_form, post_form, say_retry\n\n# Local mode. In Server mode, use the address of the CapSkip machine.\nasync_solver = AsyncCapSkip(host=&quot;127.0.0.1&quot;, port=8080)\n\nsolve_retrying = AsyncRetrying(\n    retry=retry_if_exception_type(\n        (NetworkException, TimeoutException, asyncio.TimeoutError)\n    )\n    | retry_if_exception(is_retryable),\n    stop=stop_after_attempt(3) | stop_after_delay(120),\n    wait=wait_random_exponential(multiplier=1, max=20),\n    before_sleep=say_retry,\n    retry_error_callback=lambda state: None,  # give up with None, no RetryError\n)\n\n\nasync def one_attempt(sitekey):\n    # A hard cap for one attempt: the SDK looks at its own deadline only\n    # at the next poll, and tenacity cannot interrupt a running attempt.\n    result = await asyncio.wait_for(async_solver.recaptcha(sitekey, FORM_URL), 45)\n    return result[&quot;code&quot;]<\/pre>\n<\/div>\n<p>The retry_error_callback returns None when the attempts run out. That works in the call form used here and in the decorator form. In the for attempt in AsyncRetrying loop form the callback runs, but its return value is thrown away and the loop just ends. The next block collects three solves at once, then posts each token with the sync function from Step 3, which blocks the event loop while it waits.<\/p>\n<div data-no-translation>\n<pre data-enlighter-language=\"python\" class=\"EnlighterJSRAW\">async def solve_many(sitekey, count):\n    jobs = [solve_retrying(one_attempt, sitekey) for _ in range(count)]\n    return await asyncio.gather(*jobs, return_exceptions=True)\n\n\nasync def main():\n    session, sitekey = open_form()\n    outcomes = await solve_many(sitekey, 3)\n    for number, token in enumerate(outcomes, 1):\n        if not isinstance(token, str):\n            print(f&quot;form {number}: no token ({token!r})&quot;)\n            continue\n        reply = post_form(session, token, f&quot;alice{number}&quot;, &quot;Hello&quot;)\n        print(f&quot;form {number}:&quot;, &quot;saved&quot; if &quot;Message saved&quot; in reply.text else &quot;refused&quot;)\n\n\nif __name__ == &quot;__main__&quot;:\n    asyncio.run(main())<\/pre>\n<\/div>\n<p>Three solves with a mock delay of 1 second finished in 1.7 to 2.2 seconds overlapped, against 5.3 seconds one after another with the sync client. With the first task unsolvable it used 4 tasks, and all three form posts were saved. With every attempt unsolvable, 9 tasks ended in three None values. With a wrong key, 3 ApiException objects came back as results and nothing was retried. For a bigger pool and a semaphore, see <a href=\"https:\/\/capskip.com\/solve-captchas-parallel-python\/\">solving captchas in parallel with Python<\/a>.<\/p>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">Common errors<\/h2>\n<table>\n<thead>\n<tr>\n<th>Symptom<\/th>\n<th>Cause<\/th>\n<th>Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>tenacity.RetryError instead of an SDK exception<\/td>\n<td>reraise is not set<\/td>\n<td>Pass reraise=True, or read last_attempt.exception() from the RetryError<\/td>\n<\/tr>\n<tr>\n<td>A wrong key is retried three times<\/td>\n<td>The predicate matches every ApiException<\/td>\n<td>Match only the retryable codes, as is_retryable does<\/td>\n<\/tr>\n<tr>\n<td>The run outlasts stop_after_delay<\/td>\n<td>The check happens after an attempt ends<\/td>\n<td>Lower the SDK timeout, or wrap the async call in asyncio.wait_for<\/td>\n<\/tr>\n<tr>\n<td>One solve per form post retry<\/td>\n<td>One decorator around solve and post<\/td>\n<td>Split them, as in Steps 2 and 3<\/td>\n<\/tr>\n<tr>\n<td>The event loop stalls during a retry<\/td>\n<td>A sync decorated function sleeps inside a coroutine<\/td>\n<td>Use AsyncRetrying with the async client<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">FAQ<\/h2>\n<details style=\"border:1px solid #e2e5ee;border-radius:10px;padding:14px 18px;margin:0 0 12px;\">\n<summary style=\"cursor:pointer;\">\n<h3 style=\"font-size:1.15rem;line-height:1.4;display:inline;margin:0;\">Is a retry the answer to a block page?<\/h3>\n<\/summary>\n<p style=\"margin:12px 0 0;\">No. A block that comes back on every attempt is a decision, and repeating the request only repeats it. Classify the answer first with the <a href=\"https:\/\/capskip.com\/captcha-or-block\/\">CAPTCHA or block guide<\/a>, and retry only the cases that are transient.<\/p>\n<\/details>\n<details style=\"border:1px solid #e2e5ee;border-radius:10px;padding:14px 18px;margin:0 0 12px;\">\n<summary style=\"cursor:pointer;\">\n<h3 style=\"font-size:1.15rem;line-height:1.4;display:inline;margin:0;\">Does this work for other captcha types?<\/h3>\n<\/summary>\n<p style=\"margin:12px 0 0;\">The retry rules rest on the SDK exceptions, which are the same for every method. Swap the call inside solve_token, keep the predicate, and read the page for its own field names.<\/p>\n<\/details>\n<details style=\"border:1px solid #e2e5ee;border-radius:10px;padding:14px 18px;margin:0 0 12px;\">\n<summary style=\"cursor:pointer;\">\n<h3 style=\"font-size:1.15rem;line-height:1.4;display:inline;margin:0;\">Can my retries call a CapSkip on a second PC?<\/h3>\n<\/summary>\n<p style=\"margin:12px 0 0;\">Yes. On the CapSkip machine, switch to Server mode, then use that machine&#8217;s address as host in both clients, adding your key as apiKey when API Key Validation is on. Starting Server mode opens the CapSkip port to any address, so keep strangers out with a Windows Firewall block rule for their addresses. A narrower allow rule would restrict nothing. A switched-off or unreachable server PC gives a NetworkException after about 21 seconds on Windows (my machine, Python 3.14.0). Only a server that accepts the connection and never replies blocks the sync client for good.<\/p>\n<\/details>\n<h2 style=\"font-size:1.6rem;line-height:1.35;\">The short version<\/h2>\n<p>A tenacity captcha retry works when each step is retried for its own failures: a new task for an unsolvable or timed-out solve, the same token for a busy site, a fresh solve only when the token is refused. A flat-license <a href=\"https:\/\/capskip.com\/\">captcha bypass<\/a> tool on your own PC makes that cheap to do, though each task still occupies the app. The <a href=\"https:\/\/tenacity.readthedocs.io\/\" rel=\"noopener nofollow\" target=\"_blank\">tenacity documentation<\/a> lists every stop, wait and retry helper used here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u54ea\u4e9b CapSkip SDK \u9519\u8bef\u503c\u5f97\u91cd\u8bd5\uff0c\u4e3a\u4ec0\u4e48\u8bc6\u522b\u548c\u8868\u5355 POST \u8bf7\u6c42\u9700\u8981\u5404\u81ea\u72ec\u7acb\u7684 tenacity \u88c5\u9970\u5668\uff0c\u4ee5\u53ca stop_after_delay \u771f\u6b63\u9650\u5236\u7684\u662f\u4ec0\u4e48\u3002\u9488\u5bf9\u6a21\u62df\u670d\u52a1\u6d4b\u5f97\uff0c\u540c\u6b65\u548c\u5f02\u6b65\u90fd\u6709\u3002<\/p>","protected":false},"author":1,"featured_media":28710,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"Tenacity CAPTCHA Retry in Python: Two Decorators | CapSkip","rank_math_description":"Tenacity captcha retry in Python: one decorator for the CapSkip solve, one for the form post, so a busy site never costs a second solve. Copy the script.","rank_math_focus_keyword":"tenacity captcha retry","footnotes":""},"categories":[70],"tags":[],"class_list":["post-28711","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-captcha"],"_links":{"self":[{"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/posts\/28711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/comments?post=28711"}],"version-history":[{"count":1,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/posts\/28711\/revisions"}],"predecessor-version":[{"id":28764,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/posts\/28711\/revisions\/28764"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/media\/28710"}],"wp:attachment":[{"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/media?parent=28711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/categories?post=28711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/capskip.com\/zh\/wp-json\/wp\/v2\/tags?post=28711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}