binary-husky/gpt_academic · warning · ValueError

不支持的格式: {path.suffix}. 支持的格式: {', '.join(sorted(self.SUPPORT

Error message

不支持的格式: {path.suffix}. 支持的格式: {', '.join(sorted(self.SUPPORTED_EXTENSIONS))}

What it means

Final precondition of MarkdownConverter._validate_file: the suffix is not in SUPPORTED_EXTENSIONS, which for this class is exactly {'.pdf'}. ValueError reports the suffix and the supported list. This converter is PDF-only despite living under the markitdown module — other markitdown-supported types (docx, pptx, xlsx…) are rejected here by design.

Source

Thrown at crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py:136

        path = Path(file_path).resolve()

        if not path.exists():
            raise ValueError(f"文件不存在: {path}")

        if not path.is_file():
            raise ValueError(f"不是一个文件: {path}")

        if not os.access(path, os.R_OK):
            raise PermissionError(f"没有读取权限: {path}")

        file_size_mb = path.stat().st_size / (1024 * 1024)
        if file_size_mb > max_size_mb:
            raise ValueError(
                f"文件大小 ({file_size_mb:.1f}MB) 超过限制 {max_size_mb}MB"
            )

        if path.suffix.lower() not in self.SUPPORTED_EXTENSIONS:
            raise ValueError(
                f"不支持的格式: {path.suffix}. "
                f"支持的格式: {', '.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. Convert the source to PDF first (e.g. WordToPdfConverter for docx) before this converter
  2. Rename/copy to give the file a clean '.pdf' suffix if it is genuinely a PDF
  3. Route non-PDF documents to the appropriate reader class in read_fns instead

Example fix

// before
converter.convert('paper.docx')  # 不支持的格式: .docx

// after
pdf = WordToPdfConverter.convert_to_pdf('paper.docx')
converter.convert(pdf)
Defensive patterns

Strategy: type-guard

Validate before calling

if pdf_path.suffix.lower() != '.pdf':
    raise ValueError('MarkdownConverter accepts only .pdf input')

Type guard

from pathlib import Path

def is_convertible_pdf(v) -> bool:
    p = Path(v)
    return p.is_file() and p.suffix.lower() in {'.pdf'}

Try / catch

try:
    md = converter.convert(p)
except ValueError as e:
    if '不支持的格式' in str(e):
        if p.suffix.lower() in {'.docx', '.doc'}:
            p = Path(WordToPdfConverter.convert_to_pdf(p)); md = converter.convert(p)
        else: raise
    else: raise

Prevention

When it happens

Trigger: Feeding .docx/.md/.html to MarkdownConverter; extension-less PDFs; double extensions like 'file.pdf.exe' or 'file.PDF.' with a trailing dot.

Common situations: Assuming the class converts anything markitdown supports because of its name; Windows hiding extensions producing 'paper.pdf.txt'.

Related errors


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