xtekky/gpt4free · error · MissingRequirementsError
Install "beautifulsoup4" package
Error message
Install "beautifulsoup4" package
What it means
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.
Source
Thrown at g4f/Provider/needs_auth/bing/create_images.py:88
session: ClientSession, prompt: str, timeout: int = TIMEOUT_IMAGE_CREATION
) -> List[str]:
"""
Creates images based on a given prompt using Bing's service.
Args:
session (ClientSession): Active client session.
prompt (str): Prompt to generate images.
proxy (str, optional): Proxy configuration.
timeout (int): Timeout for the request.
Returns:
List[str]: A list of URLs to the created images.
Raises:
RuntimeError: If image creation fails or times out.
"""
if not has_requirements:
raise MissingRequirementsError('Install "beautifulsoup4" package')
url_encoded_prompt = quote(prompt)
payload = f"q={url_encoded_prompt}&rt=4&FORM=GENCRE"
url = f"{BING_URL}/images/create?q={url_encoded_prompt}&rt=4&FORM=GENCRE"
async with session.post(
url, allow_redirects=False, data=payload, timeout=timeout
) as response:
response.raise_for_status()
text = (await response.text()).lower()
if "0 coins available" in text:
raise RateLimitError(
"No coins left. Log in with a different account or wait a while"
)
for error in ERRORS:
if error in text:
raise RuntimeError(f"Create images failed: {error}")
if response.status != 302:
url = f"{BING_URL}/images/create?q={url_encoded_prompt}&rt=3&FORM=GENCRE"
async with session.post(View on GitHub (pinned to 973504e177)
Solutions
- pip install beautifulsoup4 (or reinstall g4f with its image extras)
- Pin beautifulsoup4 in your project requirements so deployments always include it
Example fix
# before # MissingRequirementsError: Install "beautifulsoup4" package # after (shell) pip install beautifulsoup4
Defensive patterns
Strategy: validation
Validate before calling
try:
import bs4 # noqa
has_bs4 = True
except ImportError:
has_bs4 = False
if not has_bs4:
raise SystemExit('pip install beautifulsoup4 to use Bing image creation') Type guard
def image_deps_ready() -> bool:
try:
import bs4 # noqa
return True
except ImportError:
return False Try / catch
from g4f.errors import MissingRequirementsError
try:
images = create_images(session, prompt, cookies)
except MissingRequirementsError as e:
raise SystemExit(f'Dependency missing: {e}') Prevention
- Declare optional image deps (beautifulsoup4) in your deployment requirements
- Run a dependency smoke test at container build time
When it happens
Trigger: Calling create_images / a Bing image provider without beautifulsoup4 present in the environment.
Common situations: Minimal installs of g4f that skipped extras, virtual environments created from a requirements list missing bs4.
Related errors
- Install "curl_cffi" package | pip install -U curl_cffi
- Install "webview" package
- No coins left. Log in with a different account or wait a whi
- Create images failed: {error}
- Create images failed. Code: {response.status}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/71b9fa6bde3e4fbc.
Report an issue: GitHub.