binary-husky/gpt_academic · error · ValueError

Unsupported format: {path.suffix}. Supported: {', '.join(sor

Error message

Unsupported format: {path.suffix}. Supported: {', '.join(sorted(self.SUPPORTED_EXTENSIONS))}

What it means

UnstructuredReader's English extension allowlist error: raised when path.suffix.lower() is not in SUPPORTED_EXTENSIONS. The message includes the sorted supported list so the caller knows exactly what is accepted.

Source

Thrown at crazy_functions/doc_fns/read_fns/unstructured_all/unstructured_reader.py:130

        path = Path(file_path).resolve()

        if not path.exists():
            raise ValueError(f"File not found: {path}")

        if not path.is_file():
            raise ValueError(f"Not a file: {path}")

        if not os.access(path, os.R_OK):
            raise PermissionError(f"No read permission: {path}")

        file_size_mb = path.stat().st_size / (1024 * 1024)
        if file_size_mb > max_size_mb:
            raise ValueError(
                f"File size ({file_size_mb:.1f}MB) exceeds limit of {max_size_mb}MB"
            )

        if path.suffix.lower() not in self.SUPPORTED_EXTENSIONS:
            raise ValueError(
                f"Unsupported format: {path.suffix}. "
                f"Supported: {', '.join(sorted(self.SUPPORTED_EXTENSIONS))}"
            )

        return path

    def _cleanup_text(self, text: str) -> str:
        """清理文本

        Args:
            text: 原始文本

        Returns:
            str: 清理后的文本
        """
        if self.config.text_cleanup['remove_extra_spaces']:
            text = ' '.join(text.split())

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Pre-filter input files by the supported set: {p for p in files if p.suffix.lower() in reader.SUPPORTED_EXTENSIONS}.
  2. Convert unsupported formats with pandoc/libreoffice into a supported one.
  3. Upgrade the library if newer versions support the format.
  4. Correct misnamed extensions (file content vs suffix mismatch).

Example fix

# before
for f in Path(folder).rglob('*'):
    reader.read(f)  # ValueError on .zip/.jpg sidecars

# after
ok = reader.SUPPORTED_EXTENSIONS
for f in Path(folder).rglob('*'):
    if f.is_file() and f.suffix.lower() in ok:
        reader.read(f)
Defensive patterns

Strategy: type-guard

Validate before calling

ok = reader.SUPPORTED_EXTENSIONS
if Path(fp).suffix.lower() not in ok:
    fp = convert_to(fp, target_ext='pdf')

Type guard

def ext_supported(path: str, reader) -> bool:
    from pathlib import Path
    return Path(path).suffix.lower() in reader.SUPPORTED_EXTENSIONS

Try / catch

try:
    reader.read(fp)
except ValueError as e:
    if str(e).startswith('Unsupported format'):
        convert_then_retry(fp)
    raise

Prevention

When it happens

Trigger: Feeding files with extensions outside the allowlist (.rtf, .epub, .txt where only pdf/docx/tex etc. are supported, or no extension at all); case is handled via .lower() so .PDF is fine.

Common situations: Folder-ingestion pipelines forwarding every file; users renaming files to fake extensions; versions of the reader with different supported sets than the caller assumes; dotfiles with no suffix yielding ''.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/aa42cfdc31c327ff. Report an issue: GitHub.