xtekky/gpt4free · error · RuntimeError

WebSocket error inside Cloudflare session

Error message

WebSocket error inside Cloudflare session

What it means

ensurePip first probes `python -c "import pip"`; when that fails it bootstraps via `python -m ensurepip --upgrade`. This error means the bootstrap itself exited non-zero, so the runtime has no usable pip and the subsequent g4f install cannot run.

Source

Thrown at g4f/Provider/Cloudflare.py:230

            await session.evaluate_js(js_code)

            # Yield from the queue
            last_val = None
            while True:
                try:
                    event = await asyncio.wait_for(q.get(), timeout=30.0)
                    args = event.get("args", [])
                    if args and args[0].get("type") == "string":
                        val = args[0].get("value", "")
                        if val == last_val:
                            continue
                        last_val = val
                        if val.startswith("CF_CHUNK: "):
                            yield val[10:]
                        elif val == "CF_DONE":
                            break
                        elif val == "CF_ERROR":
                            raise RuntimeError(
                                "WebSocket error inside Cloudflare session"
                            )
                except asyncio.TimeoutError:
                    raise TimeoutError("Timeout waiting for Cloudflare response")
        finally:
            session.remove_event_handler("Runtime.consoleAPICalled", q)
            await session.close()

View on GitHub (pinned to 973504e177)

Solutions

  1. Manually reproduce inside the runtime to see the real output: <python-home>/bin/python -m ensurepip --upgrade with the same PYTHONHOME pipEnv sets
  2. Verify lib/python3.14/ensurepip/_bundled/*.whl exists in the extracted runtime; if missing, the archive is incomplete — wipe python-home and re-extract
  3. Ensure no host PYTHONPATH/PYTHONHOME leaks into the child process beyond what pipEnv sets (unset them in the shell, or extend runPython's env scrub)
  4. If the pbs flavor genuinely lacks ensurepip wheels, switch the fetch script to a full pbs build that bundles them
  5. As a workaround, get-pip.py can be fetched and run inside the runtime when network is available
Defensive patterns

Strategy: validation

Validate before calling

// before ensurePip, confirm the bundled wheels exist
home := pythonHome(binDir)
wheels := filepath.Join(home, "lib", "python3.14", "ensurepip", "_bundled")
if fi, err := os.Stat(wheels); err != nil || !fi.IsDir() {
    return fmt.Errorf("ensurepip wheels missing in runtime; use a full pbs build")
}

Prevention

When it happens

Trigger: pbs runtime whose ensurepip wheels are missing or incompatible (a stripped/mini build); PYTHONHOME/PYTHONPATH from pipEnv pointing at a layout where ensurepip cannot find its bundled wheels; disk full writing pip into site-packages; python 3.14 ensurepip bug in the specific pbs build.

Common situations: Using a python-build-standalone variant that excludes pip wheels (the 'install_only' or minimal flavors); env leakage where an outer virtualenv's PYTHONPATH shadows the runtime's stdlib; partial extraction losing lib/python3.14/ensurepip/*.whl.

Related errors


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