{"record":{"id":"dd781af7bf9d03fa","repo":"binary-husky/gpt_academic","slug":"response-status-code-t-response-cont","errorCode":null,"errorMessage":"在线搜索失败，状态码: {response.status_code}\\t{response.content.decode('utf-8')}","messagePattern":"在线搜索失败，状态码: (.+?)\\\\t(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crazy_functions/Internet_GPT.py","lineNumber":166,"sourceCode":"    }\n    results = []\n    response = requests.post(url, params=params, headers=headers, proxies=proxies, timeout=30)\n    if response.status_code == 200:\n        json_result = response.json()\n        for result in json_result['results']:\n            item = {\n                \"title\": result.get(\"title\", \"\"),\n                \"source\": result.get(\"engines\", \"unknown\"),\n                \"content\": result.get(\"content\", \"\"),\n                \"link\": result[\"url\"],\n            }\n            results.append(item)\n        return results\n    else:\n        if response.status_code == 429:\n            raise ValueError(\"Searxng（在线搜索服务）当前使用人数太多，请稍后。\")\n        else:\n            raise ValueError(\"在线搜索失败，状态码: \" + str(response.status_code) + '\\t' + response.content.decode('utf-8'))\n\n\ndef scrape_text(url, proxies) -> str:\n    \"\"\"Scrape text from a webpage\n\n    Args:\n        url (str): The URL to scrape text from\n\n    Returns:\n        str: The scraped text\n    \"\"\"\n    from loguru import logger\n    headers = {\n        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36',\n        'Content-Type': 'text/plain',\n    }\n\n    # 首先采用Jina进行文本提取","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/Internet_GPT.py#L148-L184","documentation":"searxng_request() received a non-200, non-429 HTTP response and converts the status plus UTF-8 body into ValueError. This is the generic SearxNG transport/configuration failure path.","triggerScenarios":"HTTP 403 when JSON output or API access is disabled, 404 for a wrong URL/path, 400 for unsupported parameters, 500/502 for engine/server failure, or any other provider error status.","commonSituations":"SEARXNG_URLS points to the base site instead of the search endpoint or an old instance; SearXNG's search.formats does not include json; a proxy modifies or blocks the request; engines/categories are not available on that instance; the service is down.","solutions":["Run the same query against the configured URL with curl and format=json to see the raw status/body.","Correct SEARXNG_URLS and confirm the instance allows JSON responses.","Enable the requested engines/categories on the SearxNG server.","Check proxy connectivity and remove headers that the instance rejects.","Treat 5xx as transient with a retry and a fallback URL."],"exampleFix":"# before\nraise ValueError(\"在线搜索失败，状态码: \" + str(response.status_code) + '\\t' + response.content.decode('utf-8'))\n\n# after\nbody = response.content.decode(\"utf-8\", errors=\"replace\")\nraise ValueError(\n    f\"在线搜索失败，状态码: {response.status_code}; url={response.url}; body={body[:500]}\"\n)\n","handlingStrategy":"validation","validationCode":"urls = get_conf(\"SEARXNG_URLS\")\nfor base in urls:\n    probe = requests.post(base, params={\"q\": \"test\", \"format\": \"json\"}, timeout=5)\n    if probe.status_code == 200 and probe.headers.get(\"content-type\", \"\").startswith(\"application/json\"):\n        break\nelse:\n    raise RuntimeError(\"No SearxNG URL returns JSON\")\n","typeGuard":"def is_json_searxng_response(response) -> bool:\n    return (\n        response.status_code == 200\n        and response.headers.get(\"content-type\", \"\").startswith(\"application/json\")\n        and isinstance(response.json().get(\"results\"), list)\n    )\n","tryCatchPattern":"try:\n    results = searxng_request(...)\nexcept ValueError as e:\n    log_searxng_status_and_body(e)\n    raise\n","preventionTips":["Verify the exact search URL and JSON format support before configuration.","Keep proxies aligned with the network that can reach SearxNG.","Alert on repeated 403/5xx rather than silently reporting search failure.","Prefer a monitored private instance for production."],"tags":["searxng","http","configuration","search"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}