binary-husky/gpt_academic · error · ValueError
不支持的文件格式: {path.suffix}. 支持的格式: {', '.join(sorted(self.SUPPO
Error message
不支持的文件格式: {path.suffix}. 支持的格式: {', '.join(sorted(self.SUPPORTED_EXTENSIONS))} What it means
Raised by PaperMetadataExtractor._validate_file when path.suffix.lower() is not in the class-level SUPPORTED_EXTENSIONS set. It is an explicit allowlist check so unsupported formats fail fast with the supported list embedded in the message.
Source
Thrown at crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py:119
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
- Convert the file to a supported format first (e.g. pandoc for text formats, libreoffice --convert-to pdf).
- Check sorted(self.SUPPORTED_EXTENSIONS) and align the upstream file filter with it.
- Upgrade the library version if a newer release added the extension you need.
- Fix the file's extension if it is simply misnamed.
Example fix
# before
extractor.extract_metadata('paper.epub') # ValueError
# after
supported = extractor.SUPPORTED_EXTENSIONS
ext = Path(fp).suffix.lower()
if ext not in supported:
subprocess.run(['pandoc', str(fp), '-o', 'paper.md'], check=True)
fp = 'paper.md'
extractor.extract_metadata(fp) Defensive patterns
Strategy: type-guard
Validate before calling
ext = Path(fp).suffix.lower()
if ext not in extractor.SUPPORTED_EXTENSIONS:
skip_or_convert(fp, target='pdf') Type guard
def is_supported(path: str, reader) -> bool:
from pathlib import Path
return Path(path).suffix.lower() in reader.SUPPORTED_EXTENSIONS Try / catch
try:
extractor.extract_metadata(fp)
except ValueError as e:
if '不支持的文件格式' in str(e):
convert_then_retry(fp) # pandoc/libreoffice
raise Prevention
- Maintain an allowlist filter at the upload boundary.
- Convert odd formats at ingest, not at analysis time.
- Print sorted(SUPPORTED_EXTENSIONS) in your onboarding docs.
- Reject extensionless files explicitly.
When it happens
Trigger: Calling the extractor with a file whose extension is not in SUPPORTED_EXTENSIONS — e.g. .epub, .azw3, .html, .rtf, or a mislabeled file like paper.pdf.txt. Uppercase suffixes are fine (.PDF passes) because of .lower().
Common situations: Users renaming files or saving web pages as weird extensions; pipelines forwarding everything in a folder including .zip/.jpg sidecars; new format expected but the extractor version predates its support; hidden double extensions ('.pdf.exe' style mistakes).
Related errors
- Unsupported format: {path.suffix}. Supported: {', '.join(sor
- 文件大小 ({file_size_mb:.1f}MB) 超过限制 {max_size_mb}MB
- 没有读取权限: {path}
- 文件大小 ({file_size_mb:.1f}MB) 超过限制 {max_size_mb}MB
- File not found: {path}
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/bba5f62601ed6803.
Report an issue: GitHub.