binary-husky/gpt_academic · error · ValueError

未找到ID为 {paper_id} 的论文

Error message

未找到ID为 {paper_id} 的论文

What it means

ArxivSource.download_pdf resolves a paper by calling `await self.search_by_id(paper_id)`; if the search returns an empty list it raises ValueError because there is nothing to download. It does not distinguish 'bad ID' from 'arXiv API returned nothing' — search_by_id returning [] is always treated as ID-not-found.

Source

Thrown at crazy_functions/review_fns/data_sources/arxiv_source.py:309

            limit=limit,
            sort_by=sort_by,
            sort_order=sort_order
        )

    async def download_pdf(self, paper_id: str, dirpath: str = "./", filename: str = "") -> str:
        """下载论文PDF

        Args:
            paper_id: arXiv ID
            dirpath: 保存目录
            filename: 文件名,如果为空则使用默认格式:{paper_id}_{标题}.pdf

        Returns:
            保存的文件路径
        """
        papers = await self.search_by_id(paper_id)
        if not papers:
            raise ValueError(f"未找到ID为 {paper_id} 的论文")
        paper = papers[0]

        if not filename:
            # 清理标题中的非法字符
            safe_title = "".join(c if c.isalnum() else "_" for c in paper.title)
            filename = f"{paper_id}_{safe_title}.pdf"

        filepath = os.path.join(dirpath, filename)
        urlretrieve(paper.url, filepath)
        return filepath

    async def download_source(self, paper_id: str, dirpath: str = "./", filename: str = "") -> str:
        """下载论文源文件(通常是LaTeX源码)

        Args:
            paper_id: arXiv ID
            dirpath: 保存目录
            filename: 文件名,如果为空则使用默认格式:{paper_id}_{标题}.tar.gz

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Normalize the ID before calling: strip whitespace, strip the 'arxiv.org/abs/' prefix, keep formats like '2401.00001' or 'cs/0301012'.
  2. Verify the ID resolves: open https://arxiv.org/abs/<paper_id> in a browser or call search_by_id directly and inspect the result.
  3. If the ID looks valid, retry once — the arXiv API occasionally returns empty results under rate limiting (arxiv package raises/warns on 429).
  4. Handle ValueError at the call site to report 'paper not found' instead of crashing the download pipeline.

Example fix

# before
await source.download_pdf('https://arxiv.org/abs/2401.00001', './papers')

# after
import re
raw = 'https://arxiv.org/abs/2401.00001v2'
paper_id = re.sub(r'.*abs/', '', raw).strip()
papers = await source.search_by_id(paper_id)
if not papers:
    raise ValueError(f'未找到ID为 {paper_id} 的论文')
await source.download_pdf(paper_id, './papers')
Defensive patterns

Strategy: validation

Validate before calling

import re

ARXIV_ID = re.compile(r'^(\d{4}\.\d{4,5}|[a-z-]+\.[A-Z]{2}/\d{7})(v\d+)?$', re.IGNORECASE)

def normalize_arxiv_id(raw: str) -> str | None:
    raw = raw.strip().rstrip('.').split('/abs/')[-1]
    return raw if ARXIV_ID.match(raw) else None

pid = normalize_arxiv_id(user_input)
if pid is None:
    return error_response('invalid arXiv id')

Try / catch

try:
    path = await source.download_pdf(pid, dirpath)
except ValueError as e:
    if '未找到' in str(e):
        return f'paper {pid} not found on arXiv — check the ID'
    raise

Prevention

When it happens

Trigger: Passing a malformed arXiv ID ('12345', 'abc', missing version prefix like '2401.00001' vs '2401.00001v1' handled differently), an ID for a withdrawn paper, or a valid ID when the arXiv API call inside search_by_id silently returns no results (network issue parsed as empty).

Common situations: User pastes a DOI or URL fragment instead of the bare arXiv ID; ID has whitespace/newline attached; paper was withdrawn or the listing is temporarily unavailable; transient arXiv API flakiness makes search_by_id return [].

Related errors


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