{"record":{"id":"88d77f668ae4c355","repo":"binary-husky/gpt_academic","slug":"n-exceptions","errorCode":null,"errorMessage":"在线搜索失败！\\n{Exceptions}","messagePattern":"在线搜索失败！\\\\n(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crazy_functions/Internet_GPT.py","lineNumber":94,"sourceCode":"            query_json = re.sub(r\"```json|```\", \"\", query_json)\n            queries = json.loads(query_json)\n        except Exception:\n            #* 如果再次失败，直接返回原始问题\n            queries = [query]\n    links = []\n    success = 0\n    Exceptions = \"\"\n    for q in queries:\n        try:\n            link = searxng_request(q, proxies, categories, searxng_url, engines=engines)\n            if len(link) > 0:\n                links.append(link[:-5])\n                success += 1\n        except Exception:\n            Exceptions = Exception\n            pass\n    if success == 0:\n        raise ValueError(f\"在线搜索失败！\\n{Exceptions}\")\n    # * 清洗搜索结果，依次放入每组第一，第二个搜索结果，并清洗重复的搜索结果\n    seen_links = set()\n    result = []\n    for tuple in zip_longest(*links, fillvalue=None):\n        for item in tuple:\n            if item is not None:\n                link = item[\"link\"]\n                if link not in seen_links:\n                    seen_links.add(link)\n                    result.append(item)\n    return result\n\n\n@lru_cache\ndef get_auth_ip():\n    ip = check_proxy(None, return_ip=True)\n    if ip is None:\n        return '114.114.114.' + str(random.randint(1, 10))","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/Internet_GPT.py#L76-L112","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nexcept Exception:\n    Exceptions = Exception\n    pass\nif success == 0:\n    raise ValueError(f\"在线搜索失败！\\n{Exceptions}\")\n\n# after\nexcept Exception as e:\n    Exceptions += f\"{type(e).__name__}: {e}\\n\"\nif success == 0:\n    raise ValueError(f\"在线搜索失败！\\n{Exceptions or 'No search results'}\")\n","handlingStrategy":"retry","validationCode":"urls = get_conf(\"SEARXNG_URLS\")\nassert urls, \"SEARXNG_URLS is empty\"\nprobe = searxng_request(\"connectivity test\", proxies=None, categories=\"general\", searxng_url=urls[0])\n","typeGuard":"def are_search_results(value) -> bool:\n    return isinstance(value, list) and all(isinstance(x, dict) and isinstance(x.get(\"link\"), str) for x in value)\n","tryCatchPattern":"try:\n    results = search_optimizer(...)\nexcept ValueError as e:\n    results = retry_search_with_backoff(queries=[original_query], attempts=3)\n","preventionTips":["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."],"tags":["searxng","search","network","error-handling"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}