binary-husky/gpt_academic · error · PermissionError

没有读取权限: {path}

Error message

没有读取权限: {path}

What it means

Third precondition of MarkdownConverter._validate_file: os.access(path, os.R_OK) is false — the file exists and is a file but the current process cannot read it — raising PermissionError('没有读取权限: <path>').

Source

Thrown at crazy_functions/doc_fns/read_fns/markitdown/markdown_reader.py:127

            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

  1. ls -l the path and compare with the process user (id)
  2. chmod +r / chown appropriately, or run the process as a user with read access
  3. In Docker, ensure the mount is readable by the container user and SELinux labels permit it (:z on the mount)
Defensive patterns

Strategy: validation

Validate before calling

import os

if not os.access(pdf_path, os.R_OK):
    raise PermissionError(f'no read access to {pdf_path}; fix ownership/mode')

Try / catch

try:
    md = converter.convert(pdf)
except PermissionError as e:
    alert_ops(str(e))  # path included; fix ACLs/UID
    raise

Prevention

When it happens

Trigger: File owned by another user/mode 600; containerized process with mismatched UID on a bind mount; Windows ACL denial.

Common situations: Docker deployments mounting host directories; files created by root then read by an app user; SELinux denying container access.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/ae92d3dc31564b3e. Report an issue: GitHub.