{"record":{"id":"32cf7ed3296e6c7e","repo":"xtekky/gpt4free","slug":"websocket-error-inside-cloudflare-session","errorCode":null,"errorMessage":"WebSocket error inside Cloudflare session","messagePattern":"WebSocket error inside Cloudflare session","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/Cloudflare.py","lineNumber":230,"sourceCode":"            await session.evaluate_js(js_code)\n\n            # Yield from the queue\n            last_val = None\n            while True:\n                try:\n                    event = await asyncio.wait_for(q.get(), timeout=30.0)\n                    args = event.get(\"args\", [])\n                    if args and args[0].get(\"type\") == \"string\":\n                        val = args[0].get(\"value\", \"\")\n                        if val == last_val:\n                            continue\n                        last_val = val\n                        if val.startswith(\"CF_CHUNK: \"):\n                            yield val[10:]\n                        elif val == \"CF_DONE\":\n                            break\n                        elif val == \"CF_ERROR\":\n                            raise RuntimeError(\n                                \"WebSocket error inside Cloudflare session\"\n                            )\n                except asyncio.TimeoutError:\n                    raise TimeoutError(\"Timeout waiting for Cloudflare response\")\n        finally:\n            session.remove_event_handler(\"Runtime.consoleAPICalled\", q)\n            await session.close()\n","sourceCodeStart":212,"sourceCodeEnd":238,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/Cloudflare.py#L212-L238","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before ensurePip, confirm the bundled wheels exist\nhome := pythonHome(binDir)\nwheels := filepath.Join(home, \"lib\", \"python3.14\", \"ensurepip\", \"_bundled\")\nif fi, err := os.Stat(wheels); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"ensurepip wheels missing in runtime; use a full pbs build\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["pip","ensurepip","python","environment"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}