Troubleshooting

GeeTest Challenge Expired Before Submission: Timing Guide

GeeTest challenges expire quickly. If you extract the challenge parameters, wait too long, and then solve — the target site rejects the token because the challenge has expired.


GeeTest Timing

Phase Time Limit
Challenge token validity 60-120 seconds
Solve time (CaptchaAI) 10-30 seconds
Token submission window Must complete within challenge validity
Total budget ~60-90 seconds from extraction to submission

The Problem


1. Extract gt + challenge from page  ← Clock starts
2. Submit to CaptchaAI               ← Takes 1-5 seconds
3. Wait for solve                    ← Takes 10-30 seconds
4. Get token                         ← Must still be valid
5. Submit to target site             ← Must happen fast

If step 2-5 takes longer than the challenge validity, the token is rejected.


Solution: Extract and Solve Immediately

import requests
import time
import re


def extract_geetest_params(page_url, session=None):
    """Extract fresh GeeTest parameters from page."""
    s = session or requests.Session()
    resp = s.get(page_url, timeout=15)

    # Extract gt key
    gt_match = re.search(r'"gt":\s*"([^"]+)"', resp.text)
    challenge_match = re.search(r'"challenge":\s*"([^"]+)"', resp.text)

    if not gt_match or not challenge_match:
        # Try API endpoint (many sites fetch challenge via AJAX)
        api_match = re.search(r'captcha\?.*', resp.text)
        if api_match:
            api_resp = s.get(f"{page_url}/{api_match.group()}", timeout=15)
            data = api_resp.json()
            return data.get("gt"), data.get("challenge")

    if gt_match and challenge_match:
        return gt_match.group(1), challenge_match.group(1)

    return None, None


def solve_geetest_fast(api_key, page_url, session=None):
    """Extract, solve, and return GeeTest token as fast as possible."""
    s = session or requests.Session()

    # Step 1: Extract fresh parameters
    extraction_start = time.time()
    gt, challenge = extract_geetest_params(page_url, s)

    if not gt or not challenge:
        raise RuntimeError("Could not extract GeeTest parameters")

    print(f"Extracted params in {time.time() - extraction_start:.1f}s")

    # Step 2: Submit to CaptchaAI immediately
    resp = requests.post("https://ocr.captchaai.com/in.php", data={
        "key": api_key,
        "method": "geetest",
        "gt": gt,
        "challenge": challenge,
        "pageurl": page_url,
        "json": 1,
    }, timeout=30)
    result = resp.json()

    if result.get("status") != 1:
        raise RuntimeError(f"Submit error: {result.get('request')}")

    task_id = result["request"]

    # Step 3: Poll aggressively
    time.sleep(10)  # GeeTest typically takes 10-30s
    for _ in range(16):  # 80s max
        resp = requests.get("https://ocr.captchaai.com/res.php", params={
            "key": api_key,
            "action": "get",
            "id": task_id,
            "json": 1,
        }, timeout=15)
        data = resp.json()

        if data.get("status") == 1:
            total_time = time.time() - extraction_start
            print(f"Solved in {total_time:.1f}s total")

            if total_time > 90:
                print("WARNING: Challenge may have expired")

            return data["request"]

        if data["request"] != "CAPCHA_NOT_READY":
            raise RuntimeError(f"Solve error: {data['request']}")

        time.sleep(5)

    raise TimeoutError("GeeTest solve timeout")

Handling Challenge API Endpoints

Many sites fetch GeeTest challenges via an AJAX call:

def get_fresh_challenge(api_url, session):
    """Fetch a fresh GeeTest challenge from site's API."""
    resp = session.get(api_url, timeout=15)
    data = resp.json()

    return {
        "gt": data["gt"],
        "challenge": data["challenge"],
        "new_captcha": data.get("new_captcha", True),
    }


# Common API patterns:
# GET /api/captcha/init
# GET /captcha?t=TIMESTAMP
# GET /geetest/register?t=TIMESTAMP

Retry with Fresh Challenge

def solve_geetest_with_retry(api_key, page_url, challenge_api, max_attempts=3):
    """Retry GeeTest solve with fresh challenge each time."""
    session = requests.Session()

    for attempt in range(max_attempts):
        try:
            # Always get FRESH challenge
            params = get_fresh_challenge(challenge_api, session)

            # Solve
            resp = requests.post("https://ocr.captchaai.com/in.php", data={
                "key": api_key,
                "method": "geetest",
                "gt": params["gt"],
                "challenge": params["challenge"],
                "pageurl": page_url,
                "json": 1,
            }, timeout=30)
            result = resp.json()

            if result.get("status") != 1:
                print(f"Attempt {attempt + 1}: Submit error")
                continue

            task_id = result["request"]

            # Poll
            time.sleep(10)
            for _ in range(12):
                resp = requests.get("https://ocr.captchaai.com/res.php", params={
                    "key": api_key, "action": "get",
                    "id": task_id, "json": 1,
                }, timeout=15)
                data = resp.json()

                if data.get("status") == 1:
                    return data["request"]
                if data["request"] != "CAPCHA_NOT_READY":
                    break
                time.sleep(5)

        except Exception as e:
            print(f"Attempt {attempt + 1} failed: {e}")

    raise RuntimeError("Max GeeTest solve attempts exceeded")

Troubleshooting

Issue Cause Fix
Token always rejected Challenge expired during solve Extract → solve → submit in < 60s
Can't find challenge parameter Loaded via AJAX Intercept network requests
Challenge changes on each load Normal GeeTest behavior Always use fresh challenge
Same gt key, different challenge gt is static, challenge is dynamic Re-fetch challenge, keep gt

FAQ

How do I find the challenge API endpoint?

Open browser DevTools → Network tab → look for requests containing "geetest", "captcha", or "register" when the page loads. The response will contain gt and challenge.

Can I cache the gt parameter?

Yes. The gt key is usually static per site. Only the challenge token needs to be fresh. Cache gt and re-fetch challenge before each solve.

What if the site uses GeeTest v4?

GeeTest v4 uses a different API structure. Check CaptchaAI's documentation for v4-specific parameters.



Solve GeeTest fast — get CaptchaAI with 100% accuracy.

Discussions (0)

No comments yet.

Related Posts

Tutorials GeeTest Token Injection in Browser Automation Frameworks
how to inject Gee Test v 3 solution tokens into Playwright, Puppeteer, and Selenium — including the three-value response, callback triggering, and form submissi...

Learn how to inject Gee Test v 3 solution tokens into Playwright, Puppeteer, and Selenium — including the thre...

Automation Python Testing
Jan 18, 2026
API Tutorials Solve GeeTest v3 CAPTCHA with Python and CaptchaAI
Step-by-step Python tutorial for solving Gee Test v 3 slide puzzle CAPTCHAs using the Captcha AI API.

Step-by-step Python tutorial for solving Gee Test v 3 slide puzzle CAPTCHAs using the Captcha AI API. Includes...

Automation Python Testing
Mar 23, 2026
Troubleshooting CaptchaAI Wrong CAPTCHA Type Error: How to Fix
Fix wrong CAPTCHA type errors when using Captcha AI.

Fix wrong CAPTCHA type errors when using Captcha AI. Learn how to identify the correct CAPTCHA type on a page...

Automation Python reCAPTCHA v2
Feb 28, 2026
Troubleshooting GeeTest v3 Error Codes: Complete Troubleshooting Reference
Complete reference for Gee Test v 3 error codes — from registration failures to validation errors — with causes, fixes, and Captcha AI-specific troubleshooting.

Complete reference for Gee Test v 3 error codes — from registration failures to validation errors — with cause...

Automation Testing GeeTest v3
Apr 08, 2026
Tutorials Pytest Fixtures for CaptchaAI API Testing
Build reusable pytest fixtures to test CAPTCHA-solving workflows with Captcha AI.

Build reusable pytest fixtures to test CAPTCHA-solving workflows with Captcha AI. Covers mocking, live integra...

Automation Python reCAPTCHA v2
Apr 08, 2026
Troubleshooting Common GeeTest v3 Errors and Fixes
Diagnose the most common Gee Test v 3 errors — stale challenge, bad parameters, validation failures — and fix them with practical troubleshooting steps.

Diagnose the most common Gee Test v 3 errors — stale challenge, bad parameters, validation failures — and fix...

Automation Testing GeeTest v3
Jan 24, 2026
Explainers GeeTest v3 Challenge-Response Workflow: Technical Deep Dive
A technical deep dive into Gee Test v 3's challenge-response workflow — the registration API, challenge token exchange, slider verification, and how Captcha AI...

A technical deep dive into Gee Test v 3's challenge-response workflow — the registration API, challenge token...

Automation Testing GeeTest v3
Mar 02, 2026
Explainers How GeeTest v3 CAPTCHA Works
how Gee Test v 3 CAPTCHA works.

Learn how Gee Test v 3 CAPTCHA works. Understand slide puzzles, icon challenges, the verification flow, and ho...

Automation Testing GeeTest v3
Feb 13, 2026
Tutorials CAPTCHA Handling in Mobile Apps with Appium
Handle CAPTCHAs in mobile app automation using Appium and Captcha AI — extract Web sitekeys, solve, and inject tokens on Android and i OS.

Handle CAPTCHAs in mobile app automation using Appium and Captcha AI — extract Web View sitekeys, solve, and i...

Automation Python All CAPTCHA Types
Feb 13, 2026
Reference CaptchaAI CLI Tool: Command-Line CAPTCHA Solving and Testing
A reference for building and using a Captcha AI command-line tool — solve CAPTCHAs, check balance, test parameters, and integrate with shell scripts and CI/CD p...

A reference for building and using a Captcha AI command-line tool — solve CAPTCHAs, check balance, test parame...

Automation Python All CAPTCHA Types
Feb 26, 2026
Troubleshooting Turnstile Token Invalid After Solving: Diagnosis and Fixes
Fix Cloudflare Turnstile tokens that come back invalid after solving with Captcha AI.

Fix Cloudflare Turnstile tokens that come back invalid after solving with Captcha AI. Covers token expiry, sit...

Python Cloudflare Turnstile Web Scraping
Apr 08, 2026
Troubleshooting CaptchaAI API Error Handling: Complete Decision Tree
Complete decision tree for every Captcha AI API error.

Complete decision tree for every Captcha AI API error. Learn which errors are retryable, which need parameter...

Automation Python All CAPTCHA Types
Mar 17, 2026
Troubleshooting Common OCR CAPTCHA Errors and Fixes
Fix common image/OCR CAPTCHA solving errors.

Fix common image/OCR CAPTCHA solving errors. Covers wrong text, image quality issues, format errors, and tips...

Automation Image OCR
Feb 28, 2026