binary-husky/gpt_academic · error · ValueError
在线搜索失败!\n{Exceptions}
Error message
在线搜索失败!\n{Exceptions} What it means
search_optimizer() runs one SearxNG request per optimized query. If every request raises or returns no results, it raises this ValueError. The handler also has a bug: it assigns Exceptions = Exception (the class), not the caught instance, so the message does not contain the real cause.
Source
Thrown at crazy_functions/Internet_GPT.py:94
query_json = re.sub(r"```json|```", "", query_json)
queries = json.loads(query_json)
except Exception:
#* 如果再次失败,直接返回原始问题
queries = [query]
links = []
success = 0
Exceptions = ""
for q in queries:
try:
link = searxng_request(q, proxies, categories, searxng_url, engines=engines)
if len(link) > 0:
links.append(link[:-5])
success += 1
except Exception:
Exceptions = Exception
pass
if success == 0:
raise ValueError(f"在线搜索失败!\n{Exceptions}")
# * 清洗搜索结果,依次放入每组第一,第二个搜索结果,并清洗重复的搜索结果
seen_links = set()
result = []
for tuple in zip_longest(*links, fillvalue=None):
for item in tuple:
if item is not None:
link = item["link"]
if link not in seen_links:
seen_links.add(link)
result.append(item)
return result
@lru_cache
def get_auth_ip():
ip = check_proxy(None, return_ip=True)
if ip is None:
return '114.114.114.' + str(random.randint(1, 10))View on GitHub (pinned to d6bde0fa54)
Solutions
- Call searxng_request(query, proxies, 'general') directly and inspect the actual exception/status code.
- Verify SEARXNG_URLS points to reachable SearxNG search endpoints with JSON format enabled.
- Fix the exception capture with 'except Exception as e' and aggregate the real messages.
- Retry 429/5xx/network failures with exponential backoff or try another configured URL.
- Reduce the number of optimized queries and verify proxy settings.
Example fix
# before
except Exception:
Exceptions = Exception
pass
if success == 0:
raise ValueError(f"在线搜索失败!\n{Exceptions}")
# after
except Exception as e:
Exceptions += f"{type(e).__name__}: {e}\n"
if success == 0:
raise ValueError(f"在线搜索失败!\n{Exceptions or 'No search results'}")
Defensive patterns
Strategy: retry
Validate before calling
urls = get_conf("SEARXNG_URLS")
assert urls, "SEARXNG_URLS is empty"
probe = searxng_request("connectivity test", proxies=None, categories="general", searxng_url=urls[0])
Type guard
def are_search_results(value) -> bool:
return isinstance(value, list) and all(isinstance(x, dict) and isinstance(x.get("link"), str) for x in value)
Try / catch
try:
results = search_optimizer(...)
except ValueError as e:
results = retry_search_with_backoff(queries=[original_query], attempts=3)
Prevention
- Health-check every configured SearxNG URL at startup.
- Aggregate and log real per-query exceptions.
- Cap optimized query count to avoid rate limits.
- Fall back to the original user query if LLM query optimization fails.
When it happens
Trigger: All calls to searxng_request fail with timeout, connection error, HTTP 429/5xx, unsupported category, or bad SEARXNG_URLS; or every call returns an empty list. This can happen for every query generated from the LLM JSON.
Common situations: SEARXNG_URLS is empty, outdated, or points to an instance where JSON output is disabled; a proxy cannot reach the instance; public SearxNG rate limiting; search engines are temporarily broken; LLM query optimization returned malformed or unsuitable queries.
Related errors
- 不支持的检索类型
- Searxng(在线搜索服务)当前使用人数太多,请稍后。
- 在线搜索失败,状态码: {response.status_code}\t{response.content.decode
- Failed to generate image, please try again later: {str(e)}
- 无法下载资源{txt},请检查。
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/88d77f668ae4c355.
Report an issue: GitHub.