{"record":{"id":"87e2cbdfc45aadcc","repo":"binary-husky/gpt_academic","slug":"error","errorCode":null,"errorMessage":"不支持的检索类型","messagePattern":"不支持的检索类型","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"crazy_functions/Internet_GPT.py","lineNumber":141,"sourceCode":"    if engines == \"Mixed\":\n        engines = None\n\n    if categories == 'general':\n        params = {\n            'q': query,         # 搜索查询\n            'format': 'json',   # 输出格式为JSON\n            'language': 'zh',   # 搜索语言\n            'engines': engines,\n        }\n    elif categories == 'science':\n        params = {\n            'q': query,         # 搜索查询\n            'format': 'json',   # 输出格式为JSON\n            'language': 'zh',   # 搜索语言\n            'categories': 'science'\n        }\n    else:\n        raise ValueError('不支持的检索类型')\n\n    headers = {\n        'Accept-Language': 'zh-CN,zh;q=0.9',\n        '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',\n        'X-Forwarded-For': get_auth_ip(),\n        'X-Real-IP': get_auth_ip()\n    }\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            }","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/Internet_GPT.py#L123-L159","documentation":"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.","triggerScenarios":"A caller passes 'images', 'news', 'videos', 'files', an uppercase value, a typo, or None as categories.","commonSituations":"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.","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."],"exampleFix":"# before\nif categories == 'general':\n    ...\nelif categories == 'science':\n    ...\nelse:\n    raise ValueError('不支持的检索类型')\n\n# after\ncategories = (categories or 'general').strip().lower()\nif categories not in {'general', 'science'}:\n    raise ValueError(f\"不支持的检索类型: {categories}; use general or science\")\n","handlingStrategy":"validation","validationCode":"categories = (categories or \"general\").strip().lower()\nif categories not in {\"general\", \"science\"}:\n    raise ValueError(f\"Unsupported SearxNG category: {categories}\")\nresults = searxng_request(query, proxies, categories)\n","typeGuard":"def is_supported_searxng_category(categories) -> bool:\n    return isinstance(categories, str) and categories.strip().lower() in {\"general\", \"science\"}\n","tryCatchPattern":"try:\n    results = searxng_request(...)\nexcept ValueError as e:\n    if \"不支持的检索类型\" in str(e):\n        results = searxng_request(query, proxies, \"general\")\n    else:\n        raise\n","preventionTips":["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."],"tags":["searxng","validation","search","arguments"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}