{"record":{"id":"c9487e34265c1c11","repo":"fish2018/pansou","slug":"d-c9487e","errorCode":null,"errorMessage":"搜索请求返回状态码: %d","messagePattern":"搜索请求返回状态码: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/panwiki/panwiki.go","lineNumber":246,"sourceCode":"\t\t}\n\t}\n\t\n\t// Step 2: 请求实际的搜索结果页面\n\treq2, err := http.NewRequest(\"GET\", searchURL, nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"创建搜索请求失败: %w\", err)\n\t}\n\t\n\tp.setRequestHeaders(req2)\n\t\n\tresp2, err := client.Do(req2)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"搜索请求失败: %w\", err)\n\t}\n\tdefer resp2.Body.Close()\n\t\n\tif resp2.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"搜索请求返回状态码: %d\", resp2.StatusCode)\n\t}\n\t\n\t// 解析搜索结果\n\tdoc, err := goquery.NewDocumentFromReader(resp2.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"解析HTML失败: %w\", err)\n\t}\n\t\n\treturn p.extractSearchResults(doc), nil\n}\n\n// setRequestHeaders 设置请求头\nfunc (p *PanwikiPlugin) setRequestHeaders(req *http.Request) {\n\treq.Header.Set(\"User-Agent\", UserAgent)\n\treq.Header.Set(\"Referer\", p.currentBaseURL+\"/\")\n\treq.Header.Set(\"Accept\", \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\")\n\treq.Header.Set(\"Accept-Language\", \"zh-CN,zh;q=0.9,en;q=0.8\")\n\treq.Header.Set(\"Cache-Control\", \"no-cache\")","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/panwiki/panwiki.go#L228-L264","documentation":"The results-page request completed but returned a status other than 200. searchPage requires exactly http.StatusOK to parse results, so any 3xx/4xx/5xx (after redirect handling was reset) aborts with \"搜索请求返回状态码: %d\".","triggerScenarios":"resp2.StatusCode != 200 — e.g. 302 back to a captcha/login page, 403 from anti-bot (Cloudflare/WAF), 404 because the searchid expired, 429 rate limiting, or 502/503 upstream errors.","commonSituations":"Search ID expired between the two requests; too-frequent searches triggering WAF blocks; site requires login for search; server-side outage (5xx).","solutions":["Log the status code and response body to see what the server returned.","Handle 302 by following to a captcha/login flow or re-running the search to get a fresh searchid.","Reduce request rate / add delays and caching to avoid WAF 403/429.","Update headers/cookies if the site added bot protection.","Check site availability status for 5xx before blaming the plugin."],"exampleFix":"// before\nif resp2.StatusCode != http.StatusOK {\n    return nil, fmt.Errorf(\"搜索请求返回状态码: %d\", resp2.StatusCode)\n}\n// after\nif resp2.StatusCode != http.StatusOK {\n    body, _ := io.ReadAll(io.LimitReader(resp2.Body, 512))\n    return nil, fmt.Errorf(\"搜索请求返回状态码: %d, body: %s\", resp2.StatusCode, body)\n}","handlingStrategy":"retry","validationCode":"// Go: check site availability before calling the plugin\nresp, err := http.Get(baseURL)\nif err != nil || resp.StatusCode >= 500 {\n    return nil, fmt.Errorf(\"panwiki site currently unhealthy\")\n}","typeGuard":null,"tryCatchPattern":"results, err := plugin.Search(keyword, page)\nif err != nil {\n    var statusErr interface{ Error() string }\n    if strings.Contains(err.Error(), \"搜索请求返回状态码: 403\") || strings.Contains(err.Error(), \"状态码: 429\") {\n        // back off significantly; you are being rate limited/blocked\n    }\n    return err\n}","preventionTips":["Rate-limit searches and cache results to avoid WAF triggers.","Send realistic browser headers and keep them updated.","Handle login-required flows if the site gates search behind auth.","Alert on sustained non-200 responses as upstream breakage."],"tags":["http","scraping","go","anti-bot"],"backgroundTag":"http-non-200-response","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}