{"record":{"id":"7bd187d897661742","repo":"xtekky/gpt4free","slug":"message-or-html","errorCode":null,"errorMessage":"{message or html}","messagePattern":"\\{message or html\\}","errorType":"exception","errorClass":"CloudflareError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/Qwen.py","lineNumber":431,"sourceCode":"                \"\"\"window.baxiaCommon.getUA()\"\"\", await_promise=True\r\n            )\r\n            if isinstance(captcha, str):\r\n                grecaptcha.append(captcha)\r\n            else:\r\n                raise Exception(captcha)\r\n\r\n        args = await get_args_from_nodriver(cls.url, proxy=proxy, callback=callback)\r\n\r\n        return args, next(iter(grecaptcha))\r\n\r\n    @classmethod\r\n    async def raise_for_status(cls, response, message=None):\r\n        await raise_for_status(response, message)\r\n        content_type = response.headers.get(\"content-type\", \"\")\r\n        if content_type.startswith(\"text/html\"):\r\n            html = (await response.text()).strip()\r\n            if html.startswith(\"<!doctypehtml>\") and \"aliyun_waf_aa\" in html:\r\n                raise CloudflareError(message or html)\r\n\r\n    @classmethod\r\n    def _get_headers(cls, token=None):\r\n        data = generate_cookies()\r\n        # args,ua  = await cls.get_args(proxy, **kwargs)\r\n        headers = {\r\n            \"User-Agent\": \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36\",\r\n            \"Accept\": \"*/*\",\r\n            \"Accept-Language\": \"en-US,en;q=0.5\",\r\n            \"Origin\": cls.url,\r\n            \"Referer\": f\"{cls.url}/\",\r\n            \"Content-Type\": \"application/json\",\r\n            \"Sec-Fetch-Dest\": \"empty\",\r\n            \"Sec-Fetch-Mode\": \"cors\",\r\n            \"Sec-Fetch-Site\": \"same-origin\",\r\n            \"Connection\": \"keep-alive\",\r\n            \"X-Requested-With\": \"XMLHttpRequest\",\r\n            \"Cookie\": f'ssxmod_itna={data[\"ssxmod_itna\"]};ssxmod_itna2={data[\"ssxmod_itna2\"]}',\r","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/Qwen.py#L413-L449","documentation":"Raised as CloudflareError by Qwen.raise_for_status when a response has content-type text/html whose body starts with '<!doctypehtml>' and contains 'aliyun_waf_aa' — i.e. Alibaba's WAF (Aliyun) served a browser challenge page instead of API JSON. The message is the passed message or the raw HTML. This is distinct from real Cloudflare but mapped to the same error class.","triggerScenarios":"Any Qwen API call (headers fetch, chat creation, completion) answered by Aliyun WAF with an HTML interstitial: flagged cookies, flagged bx-umidtoken, datacenter IP reputation, or request bursts.","commonSituations":"Reusing cached cookies/tokens too long (the class caches _midtoken across requests); proxy exit IP on Aliyun blocklists; high request rate; running from cloud VMs.","solutions":["Back off and retry with fresh identity: the loop resets midtoken on failure but cookies may need regeneration — restart the client/session.","Switch to a residential/cleaner proxy IP.","Slow down request cadence.","Update g4f — WAF header/cookie recipes (bx-umidtoken, cookies) are updated as Aliyun changes them."],"exampleFix":"# before\nr = await Qwen.create_async_generator(model, msgs)\n\n# after\nfrom g4f.errors import CloudflareError\nfor attempt in range(3):\n    try:\n        r = await Qwen.create_async_generator(model, msgs, proxy=residential_proxy)\n        break\n    except CloudflareError:\n        await asyncio.sleep(30)","handlingStrategy":"retry","validationCode":null,"typeGuard":"def is_waf_block(exc: Exception) -> bool:\n    from g4f.errors import CloudflareError\n    return isinstance(exc, CloudflareError)","tryCatchPattern":"from g4f.errors import CloudflareError\nfor attempt in range(3):\n    try:\n        r = await Qwen.create_async_generator(model, msgs, proxy=clean_proxy)\n        break\n    except CloudflareError:\n        if attempt == 2:\n            raise\n        await asyncio.sleep(30)  # let WAF scoring decay; rotate proxy if possible","preventionTips":["Rotate proxy IPs when WAF interstitials appear","Don't cache cookies/tokens across long sessions","Pace requests to stay under WAF scoring","Remember this is Aliyun WAF mapped to CloudflareError — Cloudflare-specific fixes won't help"],"tags":["qwen","waf","cloudflare","anti-bot","aliyun","proxy"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}