fish2018/pansou · error
[ ] 搜索请求HTTP状态错误
Error message
[%s] 搜索请求HTTP状态错误: %d
What it means
executeSearch rejects the search response when the HTTP status is not 200. The plugin expects a JSON body and only accepts an exact 200; anything else (403 anti-bot, 4xx validation, 5xx outage) aborts parsing and reports the status code.
Solutions
- Log the status code and response body to identify the server's complaint
- Re-fetch the DToken (clear the token cache) if the status is 401/403, since an expired token commonly causes it
- Check rate limits and reduce request frequency or rotate IP/proxy on 429/403
- Retry later on 5xx; verify the search endpoint still exists if you get persistent 404s
Example fix
// before
if resp.StatusCode != 200 {
return nil, fmt.Errorf("[%s] 搜索请求HTTP状态错误: %d", p.Name(), resp.StatusCode)
}
// after
if resp.StatusCode == 401 || resp.StatusCode == 403 {
p.tokenCache.Delete(cacheKey) // force token refresh on next call
return nil, fmt.Errorf("[%s] 搜索请求HTTP状态错误: %d (token可能已失效, 将重新获取)", p.Name(), resp.StatusCode)
}
if resp.StatusCode != 200 {
return nil, fmt.Errorf("[%s] 搜索请求HTTP状态错误: %d", p.Name(), resp.StatusCode)
} Defensive patterns
Strategy: retry
Try / catch
var se *StatusError
if errors.As(err, &se) {
switch {
case se.Code == 401 || se.Code == 403:
invalidateToken(); return retryOnce()
case se.Code == 429:
return retryAfter(se.RetryAfter)
case se.Code >= 500:
return retryWithBackoff()
}
return nil, err
} Prevention
- Automatically refresh the DToken on 401/403 responses
- Log status + body snippet for every non-200 to speed triage
- Respect 429 Retry-After headers and add client-side rate limiting
- Alert on 5xx rates to detect upstream outages early
When it happens
Trigger: doRequestWithRetry succeeded but resp.StatusCode != 200 on the search POST — e.g. 403 from WAF, 400 from an expired/invalid DToken2, 500 from the search backend.
Common situations: Token expired between fetch and search yielding 401/403; anti-bot challenge on the API endpoint; upstream search service outage (5xx); request rate limited (429).
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/2386a0a702db3e91.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/xys/xys.go:268
// 设置完整的请求头
req.Header.Set("User-Agent", UserAgent)
req.Header.Set("Accept", "application/json, text/plain, */*")
req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
req.Header.Set("Connection", "keep-alive")
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Referer", BaseURL+"/")
req.Header.Set("Origin", BaseURL)
req.Header.Set("X-Requested-With", "XMLHttpRequest")
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)
}
// 读取响应体
respBody, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("[%s] 读取响应体失败: %w", p.Name(), err)
}
// 解析JSON响应
var searchResp SearchResponse
if err := json.Unmarshal(respBody, &searchResp); err != nil {
return nil, fmt.Errorf("[%s] JSON解析失败: %w", p.Name(), err)
}
if searchResp.Code != 0 {
return nil, fmt.Errorf("[%s] 搜索API返回错误: %s", p.Name(), searchResp.Msg)
}
View on GitHub (pinned to beaa561337)