binary-husky/gpt_academic · error · ValueError
File not found: {path}
Error message
File not found: {path} What it means
UnstructuredReader's English-language counterpart of the missing-path check: _validate_file raises ValueError('File not found: ...') when Path(file_path).resolve() does not exist. Fail-fast validation done before any parsing so callers get a precise reason.
Source
Thrown at crazy_functions/doc_fns/read_fns/unstructured_all/unstructured_reader.py:115
def _validate_file(self, file_path: Union[str, Path], max_size_mb: int = 100) -> Path:
"""验证文件
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"File not found: {path}")
if not path.is_file():
raise ValueError(f"Not a file: {path}")
if not os.access(path, os.R_OK):
raise PermissionError(f"No read permission: {path}")
file_size_mb = path.stat().st_size / (1024 * 1024)
if file_size_mb > max_size_mb:
raise ValueError(
f"File size ({file_size_mb:.1f}MB) exceeds limit of {max_size_mb}MB"
)
if path.suffix.lower() not in self.SUPPORTED_EXTENSIONS:
raise ValueError(
f"Unsupported format: {path.suffix}. "
f"Supported: {', '.join(sorted(self.SUPPORTED_EXTENSIONS))}"
)View on GitHub (pinned to d6bde0fa54)
Solutions
- Verify the path exists (and is readable) before calling the reader; log the resolved absolute path.
- If the path is relative, anchor it explicitly with Path(__file__).parent / ... or a configured base dir instead of relying on CWD.
- Check mount/volume presence in containerized deployments before the read call.
- Regenerate or re-download the source file if a cleanup job removed it.
Example fix
# before
reader.read('uploads/' + name) # may resolve against wrong CWD
# after
from pathlib import Path
p = (UPLOAD_DIR / name).resolve()
if not p.exists():
raise FileNotFoundError(name)
reader.read(p) Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
p = Path(file_path).resolve()
if not p.exists():
raise FileNotFoundError(file_path) Type guard
def file_exists(path: str) -> bool:
from pathlib import Path
return Path(path).resolve().exists() Try / catch
try:
reader.read(fp)
except ValueError as e:
if str(e).startswith('File not found'):
re_acquire(fp) # re-download/regenerate
raise Prevention
- Anchor relative paths to a configured base directory.
- Verify volumes are mounted before batch runs.
- Don't reuse paths across restarts without re-checking.
- Log resolved absolute paths for every read.
When it happens
Trigger: Calling UnstructuredReader.read/extract with a path that doesn't exist on disk: typo, stale path from a previous run, file already deleted by cleanup, relative path resolved against an unexpected CWD (resolve() makes it absolute against the process CWD).
Common situations: Temp files garbage-collected between scheduling and execution; path from user input taken literally; app deployed in a container where the file lives on a volume that isn't mounted; race with antivirus/quarantine on Windows.
Related errors
- Not a file: {path}
- 没有读取权限: {path}
- No read permission: {path}
- 文件大小 ({file_size_mb:.1f}MB) 超过限制 {max_size_mb}MB
- 文件大小 ({file_size_mb:.1f}MB) 超过限制 {max_size_mb}MB
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/0deee7dc8000f506.
Report an issue: GitHub.