{"record":{"id":"6ef80dccbd7415d3","repo":"xtekky/gpt4free","slug":"glm-captcha-solving-failed-after-solve-retries-a","errorCode":null,"errorMessage":"GLM captcha solving failed after {SOLVE_RETRIES} attempts: {last_error}","messagePattern":"GLM captcha solving failed after (.+?) attempts: (.+?)","errorType":"exception","errorClass":"TimeoutError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/glm/captcha_solver.py","lineNumber":304,"sourceCode":"        try:\n            await tab.close()\n        except Exception:\n            pass\n\n\nasync def _solve_with_retry() -> str:\n    \"\"\"Solve the captcha with retry, matching SOLVE_RETRIES attempts.\"\"\"\n    last_err: Optional[Exception] = None\n    for attempt in range(1, SOLVE_RETRIES + 1):\n        try:\n            debug.log(f\"GLM captcha: solve attempt {attempt}/{SOLVE_RETRIES}\")\n            return await _solve_once()\n        except Exception as err:\n            last_err = err\n            debug.log(f\"GLM captcha: attempt {attempt} failed: {err}\")\n            if attempt < SOLVE_RETRIES:\n                await asyncio.sleep(1)\n    raise TimeoutError(\n        f\"GLM captcha solving failed after {SOLVE_RETRIES} attempts: {last_err}\"\n    ) from last_err\n\n\nasync def get_captcha_verify_param() -> str:\n    \"\"\"Return a fresh ``captcha_verify_param`` for the GLM API.\n\n    A valid token is cached for ``TOKEN_TTL_S`` seconds (45s). Concurrent\n    callers share a single solve to avoid spawning multiple browsers.\n    \"\"\"\n    if _cached_token[\"verify_param\"] and _cached_token[\"expires_at\"] > time.time():\n        return _cached_token[\"verify_param\"]\n\n    async with _get_solve_lock():\n        # Re-check inside the lock — another coroutine may have just solved it.\n        if _cached_token[\"verify_param\"] and _cached_token[\"expires_at\"] > time.time():\n            return _cached_token[\"verify_param\"]\n        verify_param = await _solve_with_retry()","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/glm/captcha_solver.py#L286-L322","documentation":"Terminal failure of the GLM captcha pipeline: _solve_with_retry() exhausted all SOLVE_RETRIES (3) attempts of _solve_once() (each attempt being a fresh tab solve) and re-raises as TimeoutError, chaining the last underlying exception. The message includes the last error so the root cause (SDK load timeout, invalid token, browser crash) is visible. Callers of get_captcha_verify_param() will see this bubble up when no cached token is valid.","triggerScenarios":"Any persistent failure inside _solve_once() repeated 3 times: SDK never loading (error 80), solver returning invalid tokens (error 81), browser launch failing entirely, or every attempt exceeding SOLVE_TIMEOUT_MS (40s). Transient single-attempt failures do NOT produce this error because of the retry loop with 1s backoff.","commonSituations":"Sustained Aliyun risk-control rejection of the headless environment (every attempt fails identically); broken Chrome/zendriver installation so each attempt dies at browser/tab setup; z.ai captcha config rotation making all retries useless until config is updated.","solutions":["Read {last_error} in the message — it names the real per-attempt failure; fix that underlying error (see errors for _solve_once: SDK load timeout / invalid token).","If last_error is browser-related, verify Chrome and zendriver are installed and launchable outside g4f first.","If last_error is captcha-related, update CAPTCHA_CONFIG and the bundled SDK to match the current z.ai page.","Increase SOLVE_RETRIES only after the per-attempt failure is transient (e.g. flaky network), not when attempts fail deterministically."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    token = await get_captcha_verify_param()\nexcept TimeoutError:\n    # captcha pipeline exhausted: fail over to another GLM access path or provider\n    token = None","preventionTips":["Treat 3 consecutive identical failures as systemic — inspect last_error instead of retrying more.","Warm the captcha token before request bursts so solve failures happen outside critical paths.","Log the chained exception (__cause__) — it distinguishes config rot from environment breakage."],"tags":["captcha","glm","retry","timeout"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}