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

  1. Call searxng_request(query, proxies, 'general') directly and inspect the actual exception/status code.
  2. Verify SEARXNG_URLS points to reachable SearxNG search endpoints with JSON format enabled.
  3. Fix the exception capture with 'except Exception as e' and aggregate the real messages.
  4. Retry 429/5xx/network failures with exponential backoff or try another configured URL.
  5. 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

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


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