{"record":{"id":"3f3c0252cdb4c279","repo":"xtekky/gpt4free","slug":"curl-cffi-is-not-available-on-this-platform","errorCode":null,"errorMessage":"curl_cffi is not available on this platform","messagePattern":"curl_cffi is not available on this platform","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"g4f/requests/curl_cffi.py","lineNumber":11,"sourceCode":"from __future__ import annotations\n\ntry:\n    from curl_cffi.requests import AsyncSession, Response\n\n    has_curl_cffi = True\nexcept ImportError:\n    # Fallback for systems where curl_cffi is not available or causes illegal instruction errors\n    class AsyncSession:\n        def __init__(self, *args, **kwargs):\n            raise ImportError(\"curl_cffi is not available on this platform\")\n\n    class Response:\n        pass\n\n    has_curl_cffi = False\n\nif has_curl_cffi:\n    try:\n        from curl_cffi import CurlMime\n\n        has_curl_mime = True\n    except ImportError:\n        has_curl_mime = False\n    try:\n        from curl_cffi import CurlWsFlag\n\n        has_curl_ws = True\n    except ImportError:","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/requests/curl_cffi.py#L1-L29","documentation":"Defined in g4f/requests/curl_cffi.py as the constructor of a stub AsyncSession class that exists only when `from curl_cffi.requests import AsyncSession` failed at import time. Instantiating it raises ImportError('curl_cffi is not available on this platform'). The stub pattern lets the module import cleanly everywhere while making any actual use fail loudly. Common root cause is curl_cffi's compiled wheel being incompatible (e.g. illegal instruction on old CPUs), not just a missing package.","triggerScenarios":"Importing symbols from g4f.requests.curl_cffi and constructing AsyncSession on a machine where curl_cffi is uninstalled or its native wheel fails to load (unsupported CPU instructions, wrong manylinux level, broken install).","commonSituations":"Old CPUs lacking AVX/required instructions hitting curl_cffi's illegal-instruction issue; Alpine/musl images without a compatible wheel; pip resolving an old curl_cffi built for a different ABI; the comment in the source explicitly calls out the illegal-instruction fallback.","solutions":["pip install -U curl_cffi to get a wheel matching your platform.","If it still fails, test `python -c \"import curl_cffi\"` — an illegal instruction or ImportError confirms a binary mismatch; try a different version (pip install 'curl_cffi==<older>') or a manylinux-compatible base image.","Switch the g4f backend to aiohttp (uninstall/avoid curl_cffi path) which needs no compiled curl.","On musl/Alpine, prefer a glibc-based image (python:3.x-slim) for wheel compatibility."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from g4f.requests.curl_cffi import has_curl_cffi\n\nif not has_curl_cffi:\n    # use aiohttp backend instead, or fail fast with install instructions\n    raise SystemExit(\"pip install -U curl_cffi\")","typeGuard":null,"tryCatchPattern":"try:\n    s = AsyncSession()\nexcept ImportError as e:\n    if \"curl_cffi\" in str(e):\n        from g4f.requests.aiohttp import StreamSession as FallbackSession  # non-impersonated fallback\n        s = FallbackSession()","preventionTips":["Feature-detect has_curl_cffi at startup instead of waiting for a constructor failure.","Verify `import curl_cffi` in CI for every target platform/image.","On musl or old-CPU hosts, prefer glibc images or pin a curl_cffi version with compatible binaries."],"tags":["curl-cffi","missing-dependency","platform-support","binary-incompatible","import-error"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}