binary-husky/gpt_academic · warning · ValueError

文件大小 ({file_size_mb:.1f}MB) 超过限制 {max_size_mb}MB

Error message

文件大小 ({file_size_mb:.1f}MB) 超过限制 {max_size_mb}MB

What it means

Fourth precondition of MarkdownConverter._validate_file: file size in MB (st_size / 1024²) exceeds max_size_mb (a converter config value), raising ValueError with both the actual size (1 decimal) and the limit. This is a deliberate guard before invoking markitdown, because large PDFs make conversion slow/memory-heavy.

Source

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

        Raises:
            ValueError: 文件不存在、格式不支持或大小超限
            PermissionError: 没有读取权限
        """
        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:

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. If the file is legitimately large and resources allow, raise max_size_mb in the MarkdownConverterConfig passed to MarkdownConverter
  2. Split the PDF (qpdf/pypdf) into chunks under the limit and convert each
  3. Downsample/compress the PDF (ghostscript -dPDFSETTINGS=/ebook) before conversion
  4. Verify you are not hitting the check with a bloated file caused by embedded fonts/images that a cleanup pass can shrink

Example fix

// before
converter = MarkdownConverter()  # default max_size_mb
result = converter.convert(huge_pdf)  # 文件大小超过限制

// after
cfg = MarkdownConverterConfig(max_size_mb=100)
converter = MarkdownConverter(config=cfg)
result = converter.convert(huge_pdf)
Defensive patterns

Strategy: validation

Validate before calling

from pathlib import Path

LIMIT_MB = 50
size_mb = Path(pdf).stat().st_size / 1024**2
if size_mb > LIMIT_MB:
    pdf = compress_pdf(pdf)  # ghostscript /ebook or split with pypdf

Try / catch

try:
    md = converter.convert(pdf, max_size_mb=LIMIT_MB)
except ValueError as e:
    if '超过限制' in str(e):
        return split_and_convert(pdf)  # chunk the PDF under the cap
    raise

Prevention

When it happens

Trigger: Passing a large scanned PDF (tens/hundreds of MB) while max_size_mb is at its default (MarkdownConverterConfig); multi-hundred-page books; PDFs with embedded high-res images.

Common situations: Users raising the limit in config to process big papers; conversely CI configs lowering it and legitimate files suddenly rejected.

Related errors


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