xtekky/gpt4free · error · RuntimeError

curl_cffi FormData is not available on this platform

Error message

curl_cffi FormData is not available on this platform

What it means

Constructor of the stub FormData class in g4f/requests/curl_cffi.py, used when curl_cffi is missing OR the extra symbol CurlMime could not be imported (has_curl_mime is a separate flag). Instantiating it raises RuntimeError('curl_cffi FormData is not available on this platform'). FormData wraps CurlMime for multipart uploads, so multipart support depends on both curl_cffi itself and its CurlMime API being present.

Source

Thrown at g4f/requests/curl_cffi.py:165

    class StreamSession:
        def __init__(self, *args, **kwargs):
            raise ImportError("curl_cffi is not available on this platform")


if has_curl_cffi and has_curl_mime:

    class FormData(CurlMime):
        def add_field(
            self, name, data=None, content_type: str = None, filename: str = None
        ) -> None:
            self.addpart(name, content_type=content_type, filename=filename, data=data)

else:

    class FormData:
        def __init__(self) -> None:
            raise RuntimeError("curl_cffi FormData is not available on this platform")


if has_curl_cffi and has_curl_ws:

    class WebSocket:
        def __init__(self, session, url, **kwargs) -> None:
            self.session: StreamSession = session
            self.url: str = url
            if "autoping" in kwargs:
                del kwargs["autoping"]
            self.options: dict = kwargs

        async def __aenter__(self):
            self.inner = await self.session._ws_connect(self.url, **self.options)
            return self

        async def __aexit__(self, *args):
            await self.inner.aclose() if hasattr(

View on GitHub (pinned to 973504e177)

Solutions

  1. pip install -U curl_cffi to get a version that exposes CurlMime.
  2. Check both flags if diagnosing in code: g4f.requests.curl_cffi.has_curl_cffi and has_curl_mime.
  3. If multipart is required but curl_cffi cannot work on the platform, use the aiohttp FormData equivalent from the fallback backend instead.
Defensive patterns

Strategy: validation

Validate before calling

from g4f.requests.curl_cffi import has_curl_cffi, has_curl_mime

multipart_ok = has_curl_cffi and has_curl_mime

Try / catch

try:
    form = FormData()
except RuntimeError as e:
    if "FormData" in str(e):
        from aiohttp import FormData as AiohttpFormData
        form = AiohttpFormData()  # fallback multipart container
    else:
        raise

Prevention

When it happens

Trigger: Calling FormData() (or a g4f request path that uploads files) when curl_cffi is entirely absent, or when an installed curl_cffi version is old enough that `from curl_cffi import CurlMime` fails while the base package imports fine.

Common situations: Old pinned curl_cffi versions predating CurlMime; minimal installs; attempting file-upload providers on aiohttp-only environments where the curl_cffi FormData was imported unconditionally.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/a12877dfed33cf1c. Report an issue: GitHub.