{"record":{"id":"c349660a41eb2d7b","repo":"xtekky/gpt4free","slug":"curl-cffi-websocket-is-not-available-on-this-platf","errorCode":null,"errorMessage":"curl_cffi WebSocket is not available on this platform","messagePattern":"curl_cffi WebSocket is not available on this platform","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/requests/curl_cffi.py","lineNumber":204,"sourceCode":"\n        async def receive_str(self, **kwargs) -> str:\n            method = (\n                self.inner.arecv if hasattr(self.inner, \"arecv\") else self.inner.recv\n            )\n            bytes, _ = await method()\n            return bytes.decode(errors=\"ignore\")\n\n        async def send_str(self, data: str):\n            method = (\n                self.inner.asend if hasattr(self.inner, \"asend\") else self.inner.send\n            )\n            await method(data.encode(), CurlWsFlag.TEXT)\n\nelse:\n\n    class WebSocket:\n        def __init__(self, *args, **kwargs) -> None:\n            raise RuntimeError(\"curl_cffi WebSocket is not available on this platform\")\n","sourceCodeStart":186,"sourceCodeEnd":205,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/requests/curl_cffi.py#L186-L205","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from g4f.requests.curl_cffi import has_curl_cffi, has_curl_ws\n\nws_ok = has_curl_cffi and has_curl_ws","typeGuard":null,"tryCatchPattern":"try:\n    ws = WebSocket(session, url)\nexcept RuntimeError as e:\n    if \"WebSocket\" in str(e):\n        ws = await session.ws_connect(url)  # aiohttp websocket fallback\n    else:\n        raise","preventionTips":["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."],"tags":["curl-cffi","websocket","version-mismatch","missing-dependency","platform-support"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}