fish2018/pansou · error
获取buildId时服务器返回非200状态码
Error message
获取buildId时服务器返回非200状态码: %d
What it means
getBuildId fetches the upstream site's buildId (required to build search API URLs). If the HTTP response status is not 200 and no cached buildId exists, it fails hard with this error. If a cached buildId exists, it degrades gracefully and returns the stale cache instead.
Solutions
- Check the actual status code printed and address the upstream cause (e.g. 429 → back off / slow down requests; 403 → update headers/cookies).
- Wait and retry later; the module caches a valid buildId for a period, so after one success errors become rare.
- Verify network/proxy connectivity to the upstream site from this host.
- Retry the search, which re-invokes getBaseURL and re-fetches the buildId.
Example fix
// before
return "", fmt.Errorf("获取buildId时服务器返回非200状态码: %d", resp.StatusCode)
// after
if resp.StatusCode == http.StatusTooManyRequests {
time.Sleep(2 * time.Second)
// retry once before failing
} Defensive patterns
Strategy: retry
Validate before calling
// optionally probe the upstream before calling:
resp, err := http.Get(baseSite)
if err != nil || resp.StatusCode != 200 {
// defer or skip the search call
} Try / catch
results, err := plugin.Search(ctx, kw)
if err != nil && strings.Contains(err.Error(), "非200状态码") {
// upstream returned non-200 without cached buildId: back off and retry later
time.Sleep(5 * time.Second)
results, err = plugin.Search(ctx, kw)
} Prevention
- Keep requests at a modest rate to avoid upstream rate limiting
- Monitor the log line about non-200 status — it indicates upstream trouble before hard failure
- Run from a network location not blocked by the upstream's anti-bot layer
When it happens
Trigger: Calling getBuildId (via getBaseURL/doSearch) when the upstream server returns e.g. 403, 429, 5xx, or any non-200 status, while buildIdCache is empty (first call or cache was cleared).
Common situations: Upstream site is rate-limiting or blocking the client (missing cookies/Cloudflare challenge), upstream deployed a broken build, or the cache was invalidated so there is no fallback buildId.
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/3a5f30411bdcd980.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/pansearch/pansearch.go:422
}
// 如果所有重试都失败,但有旧的缓存,使用旧的缓存(优雅降级)
if respErr != nil || resp == nil {
if buildIdCache != "" {
// fmt.Printf("请求失败,使用旧的buildId: %v\n", respErr)
return buildIdCache, nil
}
return "", fmt.Errorf("请求失败: %w", respErr)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
// 如果状态码不是200,但有旧的缓存,使用旧的缓存(优雅降级)
if buildIdCache != "" {
fmt.Printf("获取buildId时服务器返回非200状态码: %d,使用旧的buildId\n", resp.StatusCode)
return buildIdCache, nil
}
return "", fmt.Errorf("获取buildId时服务器返回非200状态码: %d", resp.StatusCode)
}
// 使用更高效的方式读取响应体
var bodyBuilder strings.Builder
_, err = io.Copy(&bodyBuilder, resp.Body)
if err != nil {
// 如果读取响应失败,但有旧的缓存,使用旧的缓存(优雅降级)
if buildIdCache != "" {
// fmt.Printf("读取响应失败,使用旧的buildId: %v\n", err)
return buildIdCache, nil
}
return "", fmt.Errorf("读取响应失败: %w", err)
}
body := bodyBuilder.String()
// 使用提取函数获取 buildId
buildId := extractBuildId(body)
View on GitHub (pinned to beaa561337)