{"record":{"id":"410d1b24047eeef7","repo":"binary-husky/gpt_academic","slug":"file-size-mb-1f-mb-max-size-mb-mb","errorCode":null,"errorMessage":"文件大小 ({file_size_mb:.1f}MB) 超过限制 {max_size_mb}MB","messagePattern":"文件大小 \\((.+?)MB\\) 超过限制 (.+?)MB","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py","lineNumber":131,"sourceCode":"\n        Raises:\n            ValueError: 文件不存在、格式不支持或大小超限\n            PermissionError: 没有读取权限\n        \"\"\"\n        path = Path(file_path).resolve()\n\n        if not path.exists():\n            raise ValueError(f\"文件不存在: {path}\")\n\n        if not path.is_file():\n            raise ValueError(f\"不是一个文件: {path}\")\n\n        if not os.access(path, os.R_OK):\n            raise PermissionError(f\"没有读取权限: {path}\")\n\n        file_size_mb = path.stat().st_size / (1024 * 1024)\n        if file_size_mb > max_size_mb:\n            raise ValueError(\n                f\"文件大小 ({file_size_mb:.1f}MB) 超过限制 {max_size_mb}MB\"\n            )\n\n        if path.suffix.lower() not in self.SUPPORTED_EXTENSIONS:\n            raise ValueError(\n                f\"不支持的格式: {path.suffix}. \"\n                f\"支持的格式: {', '.join(sorted(self.SUPPORTED_EXTENSIONS))}\"\n            )\n\n        return path\n\n    def _cleanup_text(self, text: str) -> str:\n        \"\"\"清理文本\n\n        Args:\n            text: 原始文本\n\n        Returns:","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py#L113-L149","documentation":"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.","triggerScenarios":"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.","commonSituations":"Users raising the limit in config to process big papers; conversely CI configs lowering it and legitimate files suddenly rejected.","solutions":["If the file is legitimately large and resources allow, raise max_size_mb in the MarkdownConverterConfig passed to MarkdownConverter","Split the PDF (qpdf/pypdf) into chunks under the limit and convert each","Downsample/compress the PDF (ghostscript -dPDFSETTINGS=/ebook) before conversion","Verify you are not hitting the check with a bloated file caused by embedded fonts/images that a cleanup pass can shrink"],"exampleFix":"// before\nconverter = MarkdownConverter()  # default max_size_mb\nresult = converter.convert(huge_pdf)  # 文件大小超过限制\n\n// after\ncfg = MarkdownConverterConfig(max_size_mb=100)\nconverter = MarkdownConverter(config=cfg)\nresult = converter.convert(huge_pdf)","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\nLIMIT_MB = 50\nsize_mb = Path(pdf).stat().st_size / 1024**2\nif size_mb > LIMIT_MB:\n    pdf = compress_pdf(pdf)  # ghostscript /ebook or split with pypdf","typeGuard":null,"tryCatchPattern":"try:\n    md = converter.convert(pdf, max_size_mb=LIMIT_MB)\nexcept ValueError as e:\n    if '超过限制' in str(e):\n        return split_and_convert(pdf)  # chunk the PDF under the cap\n    raise","preventionTips":["State the configured limit in your UI so users know the ceiling","Compress scanned PDFs before conversion","Split very large documents with pypdf and convert per part"],"tags":["file-size","validation","pdf","config","python"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}