binary-husky/gpt_academic · error · ValueError
无效的arXiv类别或未找到论文: {category}
Error message
无效的arXiv类别或未找到论文: {category} What it means
After fetching the category RSS successfully, the code requires feed.entries to be non-empty; an empty feed raises ValueError('无效的arXiv类别或未找到论文: {category}'). The category string was lower-cased and spaces replaced with '+' before being appended to https://rss.arxiv.org/rss/{category}, so any category token arXiv does not recognize yields a feed with no entries.
Source
Thrown at crazy_functions/review_fns/data_sources/arxiv_source.py:450
# 处理类别格式
# 1. 转换为小写
# 2. 确保多个类别之间使用+连接
category = category.lower().replace(' ', '+')
# 构建RSS feed URL
feed_url = f"https://rss.arxiv.org/rss/{category}"
print(f"正在获取RSS feed: {feed_url}") # 添加调试信息
feed = feedparser.parse(feed_url)
# 检查feed是否有效
if hasattr(feed, 'status') and feed.status != 200:
raise ValueError(f"获取RSS feed失败,状态码: {feed.status}")
if not feed.entries:
print(f"警告:未在feed中找到任何条目") # 添加调试信息
print(f"Feed标题: {feed.feed.title if hasattr(feed, 'feed') else '无标题'}")
raise ValueError(f"无效的arXiv类别或未找到论文: {category}")
if debug:
# 调试模式:只获取5篇最新论文
search = arxiv.Search(
query=f'cat:{category}',
sort_by=arxiv.SortCriterion.SubmittedDate,
sort_order=arxiv.SortOrder.Descending,
max_results=5
)
results = list(self.client.results(search))
return [self._parse_paper_data(result) for result in results]
# 正常模式:获取所有新论文
# 从RSS条目中提取arXiv ID
paper_ids = []
for entry in feed.entries:
try:
# RSS链接格式可能是以下几种:View on GitHub (pinned to d6bde0fa54)
Solutions
- Use the official category identifier with correct case, e.g. 'cs.AI', 'cs.CL', 'math.AG', 'astro-ph.GA' — do not lowercase it before passing (the method already lowercases internally, which is itself a bug for mixed-case suffixes).
- Verify the category exists on https://arxiv.org/category_taxonomy.
- For multiple categories use + between full identifiers ('cs.AI+cs.LG').
- If the category is valid, retry later — transient empty feeds occur during RSS regeneration.
Example fix
# before
category = category.lower().replace(' ', '+')
feed_url = f'https://rss.arxiv.org/rss/{category}'
# after (preserve case of the subject suffix)
category = category.strip().replace(' ', '+')
feed_url = f'https://rss.arxiv.org/rss/{category}' Defensive patterns
Strategy: validation
Validate before calling
import re
# canonical arXiv category: archive or archive.subject (subject capitalized)
ARXIV_CAT = re.compile(r'^([a-z-]+(\.[A-Z]{2})?)(\+[a-z-]+(\.[A-Z]{2})?)*$')
def valid_category(cat: str) -> bool:
return bool(ARXIV_CAT.match(cat.strip()))
if not valid_category(category):
return error_response(f"use an arXiv category like 'cs.AI', got {category!r}") Try / catch
try:
papers = await source.fetch_by_category(category)
except ValueError as e:
if '无效的arXiv类别' in str(e):
return error_response('unknown arXiv category — see https://arxiv.org/category_taxonomy')
raise Prevention
- Always pass official category IDs with correct case (cs.AI, not cs.ai).
- Beware: this method lowercases the category internally — pass correct-case values and note the bug for multi-case suffixes.
- Offer users a category picker sourced from the official taxonomy instead of free text.
When it happens
Trigger: Passing a category that is not a valid arXiv category ('machine learning', 'cs', 'AI', 'physics'), a malformed multi-category string ('cs.ai+cs.cl' — lowercase is wrong, arXiv uses cs.AI), or a valid category whose RSS momentarily returns an empty channel.
Common situations: Users typing free-text subjects instead of official archive.subject IDs; lowercasing cs.AI to cs.ai (the code lowercases the whole string, which breaks case-sensitive category suffixes); categories renamed/deprecated by arXiv.
Related errors
- 未找到ID为 {paper_id} 的论文
- 获取RSS feed失败,状态码: {feed.status}
- 不支持的检索类型
- 用户代理或助理代理未定义
- 文件大小 ({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/040d54366c2e6bc5.
Report an issue: GitHub.