xtekky/gpt4free · error · MissingRequirementsError
Missing CDP requirements
Error message
Missing CDP requirements
What it means
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.
Source
Thrown at g4f/requests/__init__.py:213
"referer": f"{url.rstrip('/')}/",
},
"proxy": proxy,
}
except Exception:
await stop_browser()
raise
async def get_args_from_cdp(
url: str,
proxy: str = None,
timeout: int = 120,
user_data_dir: str = "cdp",
headless: bool = True,
) -> dict:
"""Use the lightweight CDP client to get auth cookies and user-agent."""
if not has_cdp:
raise MissingRequirementsError("Missing CDP requirements")
debug.log(f"Open CDP session with url: {url}")
session = CDPSession(user_data_dir=user_data_dir, headless=headless)
await session.start()
try:
await session.navigate(url)
# Wait for Cloudflare/protection to pass
for _ in range(timeout):
title = await session.evaluate_js("document.title") or ""
content = await session.evaluate_js("document.body.innerText") or ""
if (
"Just a moment" not in title
and "Attention Required" not in title
and "cf-browser-verification" not in content
):View on GitHub (pinned to 973504e177)
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).
Defensive patterns
Strategy: validation
Validate before calling
from g4f.requests import has_cdp
if not has_cdp:
raise SystemExit("Run: pip install -U aiohttp websocket-client") Try / catch
from g4f.errors import MissingRequirementsError
try:
args = await get_args_from_cdp(url)
except MissingRequirementsError as e:
print(e) # informs the pip command; switch to a non-CDP flow Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Install "websocket-client" package: pip install websocket-cl
- Install "aiohttp_socks" package for proxy support
- Failed to create new tab target on port {self.port}
- CDP call {method} timed out after 30 seconds
- curl_cffi is not available on this platform
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/ab9b889c31fb7d52.
Report an issue: GitHub.