1. Root Causes for ERROR_TOKEN_EXPIRED
- Pre-solving tokens in advance and storing them in an in-memory queue
- Google reCAPTCHA v2/v3 tokens automatically expire 120 seconds after creation
- Cloudflare Turnstile clearance tokens expire within 300 seconds
2. How to Resolve & Prevent This Error
- Inject clearance tokens and submit forms immediately upon task completion
- Do not pre-solve tokens in bulk before starting your crawling workflow
- Fetch tokens just-in-time (JIT) when the challenge DOM element is actively displayed
3. Python Code Fix & Defensive Error Handling
# Just-in-time token injection to prevent expiration
from twocaptcha import TwoCaptcha
solver = TwoCaptcha("YOUR_API_KEY")
# Solve immediately before submission
token = solver.turnstile(sitekey="0x4AAAAAAADn3g5ffjW2-F1H", url="https://example.com")["code"]
# Inject immediately
page.evaluate(f'document.querySelector("[name=cf-turnstile-response]").value = "{token}"')
page.click("button[type=submit]")4. Node.js Implementation
// Just-in-time injection in Playwright
const res = await solver.cloudflareTurnstile({ pageurl, sitekey });
await page.evaluate(token => {
document.querySelector('[name=cf-turnstile-response]').value = token;
document.querySelector('form').submit();
}, res.data);5. Why 2Captcha Minimizes API Errors
2Captcha Reliability Architecture
Rank #1 Overall- No Slot Saturation: Tens of thousands of workers online 24/7 ensure sub-5 second task pickup
- Zero Fee for Failures: Unsolvable CAPTCHAs are never charged to your account balance
- Pay-As-You-Go: Deposits never expire, with a low minimum top-up of just $1.00
6. Frequently Asked Questions
How long is a reCAPTCHA token valid?
Google reCAPTCHA tokens are strictly valid for 120 seconds (2 minutes) after generation by the solver.
Can a clearance token be reused for multiple requests?
No. Clearance tokens are strictly one-time-use. Submitting the same token twice will result in rejection.