fish2018/pansou · error
[ ] 搜索请求HTTP状态错误
Error message
[%s] 搜索请求HTTP状态错误: %d
What it means
Status error in hdmoli's executeSearch (plugin/hdmoli/hdmoli.go:140): the search request succeeded at transport level but returned a non-200 status after retries. Note this record's message at the throw site is the wrapped '搜索请求失败: %w' from doRequestWithRetry; the status-check path reports the HTTP code, indicating the site refused or rate-limited the search.
Solutions
- Log the status code and response body snippet to see what the server returned
- For 403/429: slow down request rate, rotate User-Agent, or obtain needed cookies
- For 404: update the plugin's search path to the site's current URL structure
- Ensure CheckRedirect is enabled and redirect responses are followed
Example fix
// before
if resp.StatusCode != 200 {
return nil, fmt.Errorf("[%s] 搜索请求HTTP状态错误: %d", p.Name(), resp.StatusCode)
}
// after
if resp.StatusCode != 200 {
body, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
return nil, fmt.Errorf("[%s] 搜索请求HTTP状态错误: %d, body: %s", p.Name(), resp.StatusCode, body)
} Defensive patterns
Strategy: retry
Validate before calling
// Go: inspect status before treating as failure
if resp.StatusCode == http.StatusForbidden || resp.StatusCode == http.StatusTooManyRequests {
time.Sleep(backoff) // honor rate limiting before retrying
} Try / catch
if resp.StatusCode != 200 {
body, _ := io.ReadAll(io.LimitReader(resp.Body, 256))
log.Printf("hdmoli status %d: %s", resp.StatusCode, body)
// branch on code: 403/429 => backoff & rotate UA; 404 => update URL
} Prevention
- Send browser-like headers (UA, Accept, Referer) to reduce 403s
- Rate-limit requests to avoid 429
- Update selectors/URL paths when the site is redesigned
- Log response bodies on unexpected statuses
When it happens
Trigger: The server replies 403/429 (anti-bot or rate limiting), 404 (search path changed), 5xx (server error), or 301/302 that were not followed by the client.
Common situations: 缺少 Referer 触发防盗链;高频搜索被限流。
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/a3a428d63fea2498.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/hdmoli/hdmoli.go:140
}
// 设置完整的请求头
req.Header.Set("User-Agent", UserAgent)
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("Connection", "keep-alive")
req.Header.Set("Upgrade-Insecure-Requests", "1")
req.Header.Set("Cache-Control", "max-age=0")
req.Header.Set("Referer", BaseURL+"/") // HDmoli需要设置referer
resp, err := p.doRequestWithRetry(req, client)
if err != nil {
return nil, fmt.Errorf("[%s] 搜索请求失败: %w", p.Name(), err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return nil, fmt.Errorf("[%s] 搜索请求HTTP状态错误: %d", p.Name(), resp.StatusCode)
}
// 解析HTML提取搜索结果
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
return nil, fmt.Errorf("[%s] 解析搜索结果HTML失败: %w", p.Name(), err)
}
return p.parseSearchResults(doc)
}
// doRequestWithRetry 带重试机制的HTTP请求
func (p *HdmoliPlugin) doRequestWithRetry(req *http.Request, client *http.Client) (*http.Response, error) {
maxRetries := 3
var lastErr error
for i := 0; i < maxRetries; i++ {
if i > 0 {View on GitHub (pinned to beaa561337)