fish2018/pansou · error
搜索请求返回状态码
Error message
搜索请求返回状态码: %d
What it means
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".
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.
Example fix
// before
if resp2.StatusCode != http.StatusOK {
return nil, fmt.Errorf("搜索请求返回状态码: %d", resp2.StatusCode)
}
// after
if resp2.StatusCode != http.StatusOK {
body, _ := io.ReadAll(io.LimitReader(resp2.Body, 512))
return nil, fmt.Errorf("搜索请求返回状态码: %d, body: %s", resp2.StatusCode, body)
} Defensive patterns
Strategy: retry
Validate before calling
// Go: check site availability before calling the plugin
resp, err := http.Get(baseURL)
if err != nil || resp.StatusCode >= 500 {
return nil, fmt.Errorf("panwiki site currently unhealthy")
} Try / catch
results, err := plugin.Search(keyword, page)
if err != nil {
var statusErr interface{ Error() string }
if strings.Contains(err.Error(), "搜索请求返回状态码: 403") || strings.Contains(err.Error(), "状态码: 429") {
// back off significantly; you are being rate limited/blocked
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Search ID expired between the two requests; too-frequent searches triggering WAF blocks; site requires login for search; server-side outage (5xx).
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/c9487e34265c1c11.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/panwiki/panwiki.go:246
}
}
// Step 2: 请求实际的搜索结果页面
req2, err := http.NewRequest("GET", searchURL, nil)
if err != nil {
return nil, fmt.Errorf("创建搜索请求失败: %w", err)
}
p.setRequestHeaders(req2)
resp2, err := client.Do(req2)
if err != nil {
return nil, fmt.Errorf("搜索请求失败: %w", err)
}
defer resp2.Body.Close()
if resp2.StatusCode != http.StatusOK {
return nil, fmt.Errorf("搜索请求返回状态码: %d", resp2.StatusCode)
}
// 解析搜索结果
doc, err := goquery.NewDocumentFromReader(resp2.Body)
if err != nil {
return nil, fmt.Errorf("解析HTML失败: %w", err)
}
return p.extractSearchResults(doc), nil
}
// setRequestHeaders 设置请求头
func (p *PanwikiPlugin) setRequestHeaders(req *http.Request) {
req.Header.Set("User-Agent", UserAgent)
req.Header.Set("Referer", p.currentBaseURL+"/")
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
req.Header.Set("Cache-Control", "no-cache")View on GitHub (pinned to beaa561337)