xtekky/gpt4free · error · ImportError
curl_cffi is not available on this platform
Error message
curl_cffi is not available on this platform
What it means
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.
Source
Thrown at g4f/requests/curl_cffi.py:11
from __future__ import annotations
try:
from curl_cffi.requests import AsyncSession, Response
has_curl_cffi = True
except ImportError:
# Fallback for systems where curl_cffi is not available or causes illegal instruction errors
class AsyncSession:
def __init__(self, *args, **kwargs):
raise ImportError("curl_cffi is not available on this platform")
class Response:
pass
has_curl_cffi = False
if has_curl_cffi:
try:
from curl_cffi import CurlMime
has_curl_mime = True
except ImportError:
has_curl_mime = False
try:
from curl_cffi import CurlWsFlag
has_curl_ws = True
except ImportError:View on GitHub (pinned to 973504e177)
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.
Defensive patterns
Strategy: validation
Validate before calling
from g4f.requests.curl_cffi import has_curl_cffi
if not has_curl_cffi:
# use aiohttp backend instead, or fail fast with install instructions
raise SystemExit("pip install -U curl_cffi") Try / catch
try:
s = AsyncSession()
except ImportError as e:
if "curl_cffi" in str(e):
from g4f.requests.aiohttp import StreamSession as FallbackSession # non-impersonated fallback
s = FallbackSession() Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- curl_cffi WebSocket is not available on this platform
- Missing CDP requirements
- Install "websocket-client" package: pip install websocket-cl
- curl_cffi FormData is not available on this platform
- wasmtime and numpy are required for PoW solving
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/3f3c0252cdb4c279.
Report an issue: GitHub.