binary-husky/gpt_academic · error · PermissionError
没有读取权限: {path}
Error message
没有读取权限: {path} What it means
Raised by PaperMetadataExtractor._validate_file when the resolved path exists and is a regular file, but the current process lacks read permission (os.access(path, os.R_OK) is False). It is a deliberate pre-flight check before any parsing work so the caller gets a precise PermissionError instead of a cryptic parser failure.
Source
Thrown at crazy_functions/doc_fns/read_fns/unstructured_all/paper_metadata_extractor.py:110
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
def _cleanup_text(self, text: str) -> str:
"""清理文本
View on GitHub (pinned to d6bde0fa54)
Solutions
- Fix permissions on the file: chmod a+r <file> or chown to the running user, then retry.
- If the app runs under a service account, ensure uploaded/generated files are chowned to that account (e.g. in the upload handler).
- When using Docker/NFS, verify volume mount options and ACLs grant read to the container user.
- As a last resort, run the reader in a subprocess as a user with rights, or copy the file to a readable temp location first.
Example fix
# before
meta = extractor.extract('/data/papers/root-owned.pdf') # PermissionError
# after
import os, stat
p = '/data/papers/root-owned.pdf'
if not os.access(p, os.R_OK):
os.chmod(p, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
meta = extractor.extract(p) Defensive patterns
Strategy: validation
Validate before calling
import os
p = os.path.realpath(file_path)
if not os.access(p, os.R_OK):
raise PermissionError(f'fix perms first: {p}') Type guard
def is_readable(path: str) -> bool:
import os
return os.path.exists(path) and os.path.isfile(path) and os.access(path, os.R_OK) Try / catch
try:
extractor.extract(fp)
except PermissionError as e:
log_warning(f'perms: {e}'); skip_file(fp) # do not retry blindly Prevention
- Run the service under the user that owns uploaded files.
- Set explicit umask/mode on files at write time (e.g. 0o644).
- Pre-check os.access(path, os.R_OK) before calling the extractor.
- Audit volume ACLs when deploying to NFS/Docker.
When it happens
Trigger: Calling extract/metadata APIs of PaperMetadataExtractor with a file path whose mode bits (or owning user/group) deny read to the running process — e.g. chmod 000/chmod 600 file owned by another user, or a file created by root while the app runs as an unprivileged user.
Common situations: Running the service as a different user than the one that downloaded/uploaded files; files staged by a root cron job or Docker container with restrictive umask; ACLs on mounted/network volumes (NFS root_squash); read-only bind mounts without read rights.
Related errors
- No read permission: {path}
- File not found: {path}
- Not a file: {path}
- No read permission: {path}
- 没有读取权限: {path}
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/05cbb1fe3b96cbe3.
Report an issue: GitHub.