binary-husky/gpt_academic · error · ValueError
不是文件: {path}
Error message
不是文件: {path} What it means
Second precondition of PaperMetadataExtractor._validate_file: the path exists but is not a regular file (directory/symlink-to-dir/special file), raising ValueError('不是文件: <path>'). Distinguishes 'exists' from 'is a usable document' before the suffix and size checks that follow.
Source
Thrown at crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py:107
Args:
file_path: 文件路径
max_size_mb: 允许的最大文件大小(MB)
Returns:
Path: 验证后的Path对象
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
View on GitHub (pinned to d6bde0fa54)
Solutions
- Iterate the directory and call the extractor per regular file (filter path.is_file())
- Fix upstream path selection to target the document itself
- Pre-validate selections in the UI
Example fix
// before
extractor.extract('papers_dir') # 不是文件
// after
for f in sorted(Path('papers_dir').rglob('*')):
if f.is_file() and f.suffix.lower() in extractor.SUPPORTED_EXTENSIONS:
extractor.extract(f) Defensive patterns
Strategy: type-guard
Validate before calling
from pathlib import Path
p = Path(target)
if not p.is_file():
raise ValueError('pass a document file, not a directory') Type guard
from pathlib import Path
def is_regular_doc(v) -> bool:
p = Path(v)
return p.is_file() and not p.is_dir() Try / catch
try:
meta = extractor.extract(p)
except ValueError as e:
if '不是文件' in str(e) and p.is_dir():
for f in sorted(p.rglob('*')):
if f.is_file(): extractor.extract(f)
else: raise Prevention
- Expand folders into per-file extraction loops yourself
- Filter rglob/glob results with .is_file()
- Restrict UI pickers to file selection for single-document APIs
When it happens
Trigger: Passing a directory of papers to a single-file API; a symlink pointing at a directory; a FIFO/special path from a pipeline.
Common situations: Batch-processing scripts accidentally passing the folder; users selecting a library/collection node instead of the document.
Related errors
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/e73c2c612ad6b809.
Report an issue: GitHub.