xtekky/gpt4free · error · RuntimeError
curl_cffi WebSocket is not available on this platform
Error message
curl_cffi WebSocket is not available on this platform
What it means
Constructor of the stub WebSocket class in g4f/requests/curl_cffi.py, defined for the case where curl_cffi is missing or lacks WebSocket support (has_curl_ws false). Instantiation raises RuntimeError('curl_cffi WebSocket is not available on this platform'). curl_cffi's WebSocket API is relatively new, so a present-but-old curl_cffi still lands in this branch.
Source
Thrown at g4f/requests/curl_cffi.py:204
async def receive_str(self, **kwargs) -> str:
method = (
self.inner.arecv if hasattr(self.inner, "arecv") else self.inner.recv
)
bytes, _ = await method()
return bytes.decode(errors="ignore")
async def send_str(self, data: str):
method = (
self.inner.asend if hasattr(self.inner, "asend") else self.inner.send
)
await method(data.encode(), CurlWsFlag.TEXT)
else:
class WebSocket:
def __init__(self, *args, **kwargs) -> None:
raise RuntimeError("curl_cffi WebSocket is not available on this platform")
View on GitHub (pinned to 973504e177)
Solutions
- pip install -U curl_cffi so both the WebSocket API and CurlWsFlag exist.
- Verify the import chain: python -c "from curl_cffi import CurlWsFlag" — failure confirms the version is too old.
- If upgrading is impossible, use aiohttp's ws_connect for plain WebSocket needs (losing TLS impersonation).
Defensive patterns
Strategy: validation
Validate before calling
from g4f.requests.curl_cffi import has_curl_cffi, has_curl_ws ws_ok = has_curl_cffi and has_curl_ws
Try / catch
try:
ws = WebSocket(session, url)
except RuntimeError as e:
if "WebSocket" in str(e):
ws = await session.ws_connect(url) # aiohttp websocket fallback
else:
raise Prevention
- Verify `from curl_cffi import CurlWsFlag` after upgrades; WebSocket support requires a recent version.
- Detect has_curl_ws before opening impersonated websockets.
- Keep an aiohttp ws_connect fallback path for environments without modern curl_cffi.
When it happens
Trigger: Constructing WebSocket(session, url) from this module when curl_cffi is absent, or when the installed version predates the CurlWsFlag/websocket API used by the real wrapper. The failure happens at construction, before any connection attempt.
Common situations: Old curl_cffi pinned in requirements (websocket support arrived in newer releases); providers that tunnel through websockets with browser TLS fingerprints on such environments; partially upgraded environments.
Related errors
- curl_cffi is not available on this platform
- curl_cffi FormData is not available on this platform
- Missing CDP requirements
- WebSocket Error: {ws.exception()}
- Error: {msg}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/c349660a41eb2d7b.
Report an issue: GitHub.