fish2018/pansou · error
HTTP错误状态码
Error message
HTTP错误状态码: %d
What it means
fetchSearchResults requires the WordPress REST endpoint to return HTTP 200; any other status aborts with this error carrying the actual code. It indicates the search request reached the server but was rejected or the server errored.
Solutions
- Log the status code and response body snippet to identify why the server rejected the request.
- Set a browser-like User-Agent and other headers (setRequestHeaders) to pass WAF checks.
- Clamp/validate opts.Page and opts.PerPage to ranges the server accepts (e.g. per_page ≤ 100).
- Confirm the REST API is enabled on the target WordPress site (visit /wp-json/wp/v2/posts directly).
Defensive patterns
Strategy: retry
Try / catch
results, err := plugin.SearchWithResult(ctx, opts)
if err != nil && strings.Contains(err.Error(), "HTTP错误状态码") {
var sc int
fmt.Sscanf(err.Error(), "HTTP错误状态码: %d", &sc)
if sc == 429 || sc >= 500 {
// transient: retry with backoff; 4xx: fix params/headers instead
}
} Prevention
- Keep per_page within WordPress limits (≤100) and page numbers valid
- Send a browser-like User-Agent to avoid WAF blocks
- Confirm the target site has the REST API enabled before integrating
- Back off on 429/5xx rather than hammering retries
When it happens
Trigger: searchImpl's request completes but the /wp-json/wp/v2/posts endpoint returns non-200: 400 (bad per_page/page params), 403/401 (blocked or protected REST API), 404 (REST API disabled/removed), 429 or 5xx.
Common situations: Site disabled the REST API via plugin/security config; WAF blocks the client's User-Agent; requesting a page number beyond available results with some server configs returning 400; upstream outage.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/689bfcef34e4905b.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/cyg/cyg.go:155
// 创建请求对象
req, err := http.NewRequestWithContext(ctx, "GET", searchURL, nil)
if err != nil {
return nil, fmt.Errorf("创建请求失败: %w", err)
}
// 设置请求头
p.setRequestHeaders(req)
// 发送请求
resp, err := p.doRequestWithRetry(req, client)
if err != nil {
return nil, fmt.Errorf("HTTP请求失败: %w", err)
}
defer resp.Body.Close()
// 检查状态码
if resp.StatusCode != 200 {
return nil, fmt.Errorf("HTTP错误状态码: %d", resp.StatusCode)
}
// 解析响应
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("读取响应失败: %w", err)
}
var posts []CygPost
if err := json.Unmarshal(body, &posts); err != nil {
return nil, fmt.Errorf("JSON解析失败: %w", err)
}
return posts, nil
}
// fetchDownloadLinksAsync 并发获取下载链接
func (p *CygPlugin) fetchDownloadLinksAsync(client *http.Client, posts []CygPost, keyword string) []model.SearchResult {View on GitHub (pinned to beaa561337)