{"record":{"id":"e3dcc5c9e4c7d598","repo":"xtekky/gpt4free","slug":"install-beautifulsoup4-requirements-pip-instal","errorCode":null,"errorMessage":"Install \"beautifulsoup4\" requirements | pip install -U g4f[files]","messagePattern":"Install \"beautifulsoup4\" requirements \\| pip install -U g4f\\[files\\]","errorType":"exception","errorClass":"MissingRequirementsError","httpStatus":null,"severity":"warning","filePath":"g4f/tools/files.py","lineNumber":145,"sourceCode":"            f'Install \"pypdf2\" requirements | pip install -U g4f[files]'\n        )\n    elif filename.endswith(\".docx\"):\n        if has_docx:\n            return True\n        elif has_docx2txt:\n            return True\n        raise MissingRequirementsError(\n            f'Install \"docx\" requirements | pip install -U g4f[files]'\n        )\n    elif has_odfpy and filename.endswith(\".odt\"):\n        return True\n    elif has_ebooklib and filename.endswith(\".epub\"):\n        return True\n    elif has_openpyxl and filename.endswith(\".xlsx\"):\n        return True\n    elif filename.endswith(\".html\"):\n        if not has_beautifulsoup4:\n            raise MissingRequirementsError(\n                f'Install \"beautifulsoup4\" requirements | pip install -U g4f[files]'\n            )\n        return True\n    elif filename.endswith(\".zip\"):\n        return True\n    elif filename.endswith(\"package-lock.json\") and filename != FILE_LIST:\n        return False\n    else:\n        extension = os.path.splitext(filename)[1][1:]\n        if extension in PLAIN_FILE_EXTENSIONS:\n            return True\n    return False\n\n\ndef spacy_refine_chunks(source_iterator):\n    if not has_spacy:\n        raise MissingRequirementsError(\n            f'Install \"spacy\" requirements | pip install -U g4f[files]'","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/tools/files.py#L127-L163","documentation":"supports_filename raises MissingRequirementsError for .html files when beautifulsoup4 is not importable. HTML files are only accepted as parseable attachments if BeautifulSoup is available to sanitize/extract them.","triggerScenarios":"Attaching a .html file in g4f on an install lacking beautifulsoup4 — note the other file types (.odt, .epub, .xlsx) silently return False instead of raising, but .html explicitly raises.","commonSituations":"Base install without the files extra; environments where bs4 was removed; scripts assuming any text file type is accepted.","solutions":["pip install -U 'g4f[files]'.","Or pip install beautifulsoup4 directly.","Verify: python -c 'import bs4'.","Alternatively pass the extracted plain text of the HTML instead of the .html file."],"exampleFix":"# before\npip install g4f\nAttachment('page.html', open('page.html','rb'))\n\n# after\npip install -U 'g4f[files]'","handlingStrategy":"validation","validationCode":"from g4f.tools.files import supports_filename\nsupports_filename('page.html')  # raises MissingRequirementsError without beautifulsoup4","typeGuard":"from g4f.errors import MissingRequirementsError\n\ndef html_backend_available() -> bool:\n    try:\n        import bs4  # noqa\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"from g4f.errors import MissingRequirementsError\ntry:\n    supports_filename('page.html')\nexcept MissingRequirementsError as e:\n    raise SystemExit('Run: pip install -U g4f[files]') from e","preventionTips":["Install beautifulsoup4 (or g4f[files]) before accepting .html attachments","Pre-flight check file types users upload","Remember .odt/.epub/.xlsx return False silently — handle that case too","Keep optional deps declared in deployment manifests"],"tags":["missing-dependency","html","beautifulsoup4","extras"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}