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
- Manually reproduce inside the runtime to see the real output: <python-home>/bin/python -m ensurepip --upgrade with the same PYTHONHOME pipEnv sets
- Verify lib/python3.14/ensurepip/_bundled/*.whl exists in the extracted runtime; if missing, the archive is incomplete — wipe python-home and re-extract
- 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)
- If the pbs flavor genuinely lacks ensurepip wheels, switch the fetch script to a full pbs build that bundles them
- 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
- Use a python-build-standalone flavor that bundles ensurepip wheels; verify in fetch-python.sh
- Scrub host PYTHONHOME/PYTHONPATH from the child env so ensurepip resolves inside the runtime only
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
- {r.status} {response body text}
- CDP module is required for Cloudflare provider. Please ensur
- ANTIGRAVITY_SERVICE_ACCOUNT environment variable not set. Pl
- Invalid AZURE_API_KEYS environment variable
- Invalid AZURE_ROUTES environment variable format: {routes}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/32cf7ed3296e6c7e.
Report an issue: GitHub.