{"record":{"id":"ab9b889c31fb7d52","repo":"xtekky/gpt4free","slug":"missing-cdp-requirements","errorCode":null,"errorMessage":"Missing CDP requirements","messagePattern":"Missing CDP requirements","errorType":"exception","errorClass":"MissingRequirementsError","httpStatus":null,"severity":"error","filePath":"g4f/requests/__init__.py","lineNumber":213,"sourceCode":"                \"referer\": f\"{url.rstrip('/')}/\",\n            },\n            \"proxy\": proxy,\n        }\n    except Exception:\n        await stop_browser()\n        raise\n\n\nasync def get_args_from_cdp(\n    url: str,\n    proxy: str = None,\n    timeout: int = 120,\n    user_data_dir: str = \"cdp\",\n    headless: bool = True,\n) -> dict:\n    \"\"\"Use the lightweight CDP client to get auth cookies and user-agent.\"\"\"\n    if not has_cdp:\n        raise MissingRequirementsError(\"Missing CDP requirements\")\n\n    debug.log(f\"Open CDP session with url: {url}\")\n    session = CDPSession(user_data_dir=user_data_dir, headless=headless)\n    await session.start()\n\n    try:\n        await session.navigate(url)\n\n        # Wait for Cloudflare/protection to pass\n        for _ in range(timeout):\n            title = await session.evaluate_js(\"document.title\") or \"\"\n            content = await session.evaluate_js(\"document.body.innerText\") or \"\"\n\n            if (\n                \"Just a moment\" not in title\n                and \"Attention Required\" not in title\n                and \"cf-browser-verification\" not in content\n            ):","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/requests/__init__.py#L195-L231","documentation":"Raised by get_args_from_cdp() in g4f/requests/__init__.py when the module-level flag has_cdp is False. has_cdp is set at import time by trying `from .cdp import CDPSession`; if that import chain fails (typically missing aiohttp and/or websocket-client that g4f/requests/cdp.py depends on), the CDP path is disabled and this MissingRequirementsError explains that optional dependencies are absent. It is g4f's standard pattern for signaling an uninstalled optional extra.","triggerScenarios":"Calling await get_args_from_cdp(url) on an environment where `import g4f.requests.cdp` failed at startup — i.e. aiohttp or websocket-client is not installed or broken (e.g. binary-incompatible wheel). No amount of retrying at runtime changes the result because the flag was computed at import time.","commonSituations":"Installing g4f without the browser/CDP extras; running in a slim Docker image that omitted aiohttp/websocket-client; upgrading Python versions so an old aiohttp wheel fails to import with an ImportError.","solutions":["pip install -U aiohttp websocket-client and re-import the application (restart the process so has_cdp is recomputed).","Verify with `python -c \"from g4f.requests.cdp import CDPSession\"` that the import now succeeds.","If aiohttp import fails due to a broken wheel, reinstall it: pip install --force-reinstall aiohttp.","If you cannot install the extras, avoid get_args_from_cdp and use a non-CDP flow (e.g. get_nodriver with zendriver, or plain HTTP requests)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from g4f.requests import has_cdp\n\nif not has_cdp:\n    raise SystemExit(\"Run: pip install -U aiohttp websocket-client\")","typeGuard":null,"tryCatchPattern":"from g4f.errors import MissingRequirementsError\n\ntry:\n    args = await get_args_from_cdp(url)\nexcept MissingRequirementsError as e:\n    print(e)  # informs the pip command; switch to a non-CDP flow","preventionTips":["Check g4f.requests.has_cdp once at app startup and fail fast with the install command.","Pin the browser/CDP extras in requirements so environments never boot without them.","After upgrading Python, re-verify aiohttp/websocket-client import cleanly."],"tags":["missing-dependency","cdp","import-error","aiohttp","websocket"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}