xtekky/gpt4free · error · CloudflareError
{message or html}
Error message
{message or html} What it means
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.
Source
Thrown at g4f/Provider/Qwen.py:431
"""window.baxiaCommon.getUA()""", await_promise=True
)
if isinstance(captcha, str):
grecaptcha.append(captcha)
else:
raise Exception(captcha)
args = await get_args_from_nodriver(cls.url, proxy=proxy, callback=callback)
return args, next(iter(grecaptcha))
@classmethod
async def raise_for_status(cls, response, message=None):
await raise_for_status(response, message)
content_type = response.headers.get("content-type", "")
if content_type.startswith("text/html"):
html = (await response.text()).strip()
if html.startswith("<!doctypehtml>") and "aliyun_waf_aa" in html:
raise CloudflareError(message or html)
@classmethod
def _get_headers(cls, token=None):
data = generate_cookies()
# args,ua = await cls.get_args(proxy, **kwargs)
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"Origin": cls.url,
"Referer": f"{cls.url}/",
"Content-Type": "application/json",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"Connection": "keep-alive",
"X-Requested-With": "XMLHttpRequest",
"Cookie": f'ssxmod_itna={data["ssxmod_itna"]};ssxmod_itna2={data["ssxmod_itna2"]}',
View on GitHub (pinned to 973504e177)
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.
Example fix
# before
r = await Qwen.create_async_generator(model, msgs)
# after
from g4f.errors import CloudflareError
for attempt in range(3):
try:
r = await Qwen.create_async_generator(model, msgs, proxy=residential_proxy)
break
except CloudflareError:
await asyncio.sleep(30) Defensive patterns
Strategy: retry
Type guard
def is_waf_block(exc: Exception) -> bool:
from g4f.errors import CloudflareError
return isinstance(exc, CloudflareError) Try / catch
from g4f.errors import CloudflareError
for attempt in range(3):
try:
r = await Qwen.create_async_generator(model, msgs, proxy=clean_proxy)
break
except CloudflareError:
if attempt == 2:
raise
await asyncio.sleep(30) # let WAF scoring decay; rotate proxy if possible Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- {captcha}
- Failed to extract bx-umidtoken.
- The Qwen provider reached the limit Cloudflare.
- Error processing token {token}: {exc}
- Failed to obtain Turnstile token for DeepInfra request.
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/7bd187d897661742.
Report an issue: GitHub.