{"record":{"id":"9b4118428299478a","repo":"xtekky/gpt4free","slug":"the-qwen-provider-reached-the-limit-cloudflare","errorCode":null,"errorMessage":"The Qwen provider reached the limit Cloudflare.","messagePattern":"The Qwen provider reached the limit Cloudflare\\.","errorType":"exception","errorClass":"RateLimitError","httpStatus":null,"severity":"critical","filePath":"g4f/Provider/Qwen.py","lineNumber":730,"sourceCode":"                except (aiohttp.ClientResponseError, RuntimeError) as e:\r\n                    is_rate_limit = (\r\n                        isinstance(e, aiohttp.ClientResponseError) and e.status == 429\r\n                    ) or (\"RateLimited\" in str(e))\r\n                    if is_rate_limit:\r\n                        debug.log(\r\n                            f\"[Qwen] WARNING: Rate limit detected (attempt {attempt + 1}/5). Invalidating current midtoken.\"\r\n                        )\r\n                        cls._midtoken = None\r\n                        cls._midtoken_uses = 0\r\n                        conversation = None\r\n                        await asyncio.sleep(2)\r\n                        continue\r\n                    else:\r\n                        raise e\r\n            raise RateLimitError(\r\n                \"The Qwen provider reached the request limit after 5 attempts.\"\r\n            )\r\n        raise RateLimitError(\"The Qwen provider reached the limit Cloudflare.\")\r\n","sourceCodeStart":712,"sourceCodeEnd":731,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/Qwen.py#L712-L731","documentation":"Raised as RateLimitError when get_args_from_nodriver fails entirely (raises before the retry loop runs), meaning the browser-based bootstrap against chat.qwen.ai could not complete — typically because Aliyun WAF/Cloudflare blocked the browser itself. The message says 'Cloudflare' but per raise_for_status it is usually the Aliyun WAF ('aliyun_waf_aa') interstitial.","triggerScenarios":"The nodriver Chrome bootstrap failing: WAF challenge page served to the browser, nodriver/Chrome launch failure in the environment (missing browser, sandbox restrictions), or the callback timing out waiting for the baxia module.","commonSituations":"Docker/CI without a usable Chrome or with sandbox flags blocking launch; datacenter IP hard-blocked by Aliyun WAF; parallel Qwen calls racing browser bootstraps; outdated Chrome binary vs challenge requirements.","solutions":["Verify Chrome launches under nodriver in your environment (install/update the browser, allow the sandbox).","Use a residential proxy so the browser bootstrap is not WAF-blocked.","Avoid concurrent first-calls; let one bootstrap complete and reuse the harvested args.","Update g4f; bootstrap/WAF handling is patched frequently."],"exampleFix":"# before\nawait asyncio.gather(*[Qwen.create_async_generator(model, m) for m in msgs])\n\n# after - warm up once, then serialize\nawait Qwen.create_async_generator(model, [{'role':'user','content':'hi'}])  # bootstrap\nfor m in msgs:\n    await Qwen.create_async_generator(model, m)","handlingStrategy":"validation","validationCode":"import shutil\n\ndef qwen_bootstrap_possible() -> bool:\n    \"\"\"nodriver needs a Chrome/Chromium binary.\"\"\"\n    return any(shutil.which(b) for b in ('google-chrome', 'google-chrome-stable', 'chromium', 'chromium-browser'))","typeGuard":"def is_waf_bootstrap_failure(exc: Exception) -> bool:\n    from g4f.errors import RateLimitError\n    return isinstance(exc, RateLimitError) and 'Cloudflare' in str(exc)","tryCatchPattern":"from g4f.errors import RateLimitError\ntry:\n    r = await Qwen.create_async_generator(model, msgs)\nexcept RateLimitError as e:\n    if 'Cloudflare' in str(e):\n        r = await Qwen.create_async_generator(model, msgs, proxy=residential_proxy)  # fresh IP, new bootstrap\n    else:\n        raise","preventionTips":["Verify Chrome installs and launches under nodriver in your environment","Warm up the provider once, then serialize calls","Use residential proxies for the browser bootstrap","Keep browser and g4f updated against Aliyun WAF changes"],"tags":["qwen","waf","browser","bootstrap","nodriver","rate-limit"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}