{"record":{"id":"71b9fa6bde3e4fbc","repo":"xtekky/gpt4free","slug":"install-beautifulsoup4-package","errorCode":null,"errorMessage":"Install \"beautifulsoup4\" package","messagePattern":"Install \"beautifulsoup4\" package","errorType":"exception","errorClass":"MissingRequirementsError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/bing/create_images.py","lineNumber":88,"sourceCode":"    session: ClientSession, prompt: str, timeout: int = TIMEOUT_IMAGE_CREATION\n) -> List[str]:\n    \"\"\"\n    Creates images based on a given prompt using Bing's service.\n\n    Args:\n        session (ClientSession): Active client session.\n        prompt (str): Prompt to generate images.\n        proxy (str, optional): Proxy configuration.\n        timeout (int): Timeout for the request.\n\n    Returns:\n        List[str]: A list of URLs to the created images.\n\n    Raises:\n        RuntimeError: If image creation fails or times out.\n    \"\"\"\n    if not has_requirements:\n        raise MissingRequirementsError('Install \"beautifulsoup4\" package')\n    url_encoded_prompt = quote(prompt)\n    payload = f\"q={url_encoded_prompt}&rt=4&FORM=GENCRE\"\n    url = f\"{BING_URL}/images/create?q={url_encoded_prompt}&rt=4&FORM=GENCRE\"\n    async with session.post(\n        url, allow_redirects=False, data=payload, timeout=timeout\n    ) as response:\n        response.raise_for_status()\n        text = (await response.text()).lower()\n        if \"0 coins available\" in text:\n            raise RateLimitError(\n                \"No coins left. Log in with a different account or wait a while\"\n            )\n        for error in ERRORS:\n            if error in text:\n                raise RuntimeError(f\"Create images failed: {error}\")\n    if response.status != 302:\n        url = f\"{BING_URL}/images/create?q={url_encoded_prompt}&rt=3&FORM=GENCRE\"\n        async with session.post(","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/bing/create_images.py#L70-L106","documentation":"Raised as MissingRequirementsError by Bing image creation when the optional beautifulsoup4 package is not installed. The module needs it to parse the Bing results page; the check (has_requirements) runs before any HTTP call, so this is purely an environment problem.","triggerScenarios":"Calling create_images / a Bing image provider without beautifulsoup4 present in the environment.","commonSituations":"Minimal installs of g4f that skipped extras, virtual environments created from a requirements list missing bs4.","solutions":["pip install beautifulsoup4 (or reinstall g4f with its image extras)","Pin beautifulsoup4 in your project requirements so deployments always include it"],"exampleFix":"# before\n# MissingRequirementsError: Install \"beautifulsoup4\" package\n\n# after (shell)\npip install beautifulsoup4","handlingStrategy":"validation","validationCode":"try:\n    import bs4  # noqa\n    has_bs4 = True\nexcept ImportError:\n    has_bs4 = False\nif not has_bs4:\n    raise SystemExit('pip install beautifulsoup4 to use Bing image creation')","typeGuard":"def image_deps_ready() -> bool:\n    try:\n        import bs4  # noqa\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"from g4f.errors import MissingRequirementsError\ntry:\n    images = create_images(session, prompt, cookies)\nexcept MissingRequirementsError as e:\n    raise SystemExit(f'Dependency missing: {e}')","preventionTips":["Declare optional image deps (beautifulsoup4) in your deployment requirements","Run a dependency smoke test at container build time"],"tags":["dependencies","missing-package","beautifulsoup4","bing","g4f"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}