binary-husky/gpt_academic · error · ValueError
不支持的检索类型
Error message
不支持的检索类型
What it means
searxng_request() explicitly supports only categories='general' and categories='science'. Any other value reaches this ValueError. The engines argument does not add a category; it is only placed in the general-search parameter map.
Source
Thrown at crazy_functions/Internet_GPT.py:141
if engines == "Mixed":
engines = None
if categories == 'general':
params = {
'q': query, # 搜索查询
'format': 'json', # 输出格式为JSON
'language': 'zh', # 搜索语言
'engines': engines,
}
elif categories == 'science':
params = {
'q': query, # 搜索查询
'format': 'json', # 输出格式为JSON
'language': 'zh', # 搜索语言
'categories': 'science'
}
else:
raise ValueError('不支持的检索类型')
headers = {
'Accept-Language': 'zh-CN,zh;q=0.9',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
'X-Forwarded-For': get_auth_ip(),
'X-Real-IP': get_auth_ip()
}
results = []
response = requests.post(url, params=params, headers=headers, proxies=proxies, timeout=30)
if response.status_code == 200:
json_result = response.json()
for result in json_result['results']:
item = {
"title": result.get("title", ""),
"source": result.get("engines", "unknown"),
"content": result.get("content", ""),
"link": result["url"],
}View on GitHub (pinned to d6bde0fa54)
Solutions
- Pass only 'general' or 'science' to searxng_request.
- Normalize caller input with strip().lower() before the call.
- Use the engines parameter for engine selection within general search.
- Add a branch with the required SearXNG categories parameter if a new category is genuinely needed.
- Validate the category before starting LLM search optimization.
Example fix
# before
if categories == 'general':
...
elif categories == 'science':
...
else:
raise ValueError('不支持的检索类型')
# after
categories = (categories or 'general').strip().lower()
if categories not in {'general', 'science'}:
raise ValueError(f"不支持的检索类型: {categories}; use general or science")
Defensive patterns
Strategy: validation
Validate before calling
categories = (categories or "general").strip().lower()
if categories not in {"general", "science"}:
raise ValueError(f"Unsupported SearxNG category: {categories}")
results = searxng_request(query, proxies, categories)
Type guard
def is_supported_searxng_category(categories) -> bool:
return isinstance(categories, str) and categories.strip().lower() in {"general", "science"}
Try / catch
try:
results = searxng_request(...)
except ValueError as e:
if "不支持的检索类型" in str(e):
results = searxng_request(query, proxies, "general")
else:
raise
Prevention
- Normalize category strings at the UI boundary.
- Keep engine names in engines, not categories.
- Document that this wrapper supports only general and science.
- Add tests for uppercase and whitespace input.
When it happens
Trigger: A caller passes 'images', 'news', 'videos', 'files', an uppercase value, a typo, or None as categories.
Common situations: Plugin arguments are copied from a different SearXNG client; a UI dropdown value is not normalized; code assumes every SearxNG category is implemented; a caller confuses engines such as 'google' with categories.
Related errors
- 在线搜索失败!\n{Exceptions}
- Searxng(在线搜索服务)当前使用人数太多,请稍后。
- 在线搜索失败,状态码: {response.status_code}\t{response.content.decode
- 用户代理或助理代理未定义
- 文件大小 ({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/87e2cbdfc45aadcc.
Report an issue: GitHub.