fish2018/pansou · error
首页请求返回状态码
Error message
首页请求返回状态码: %d
What it means
getFormhash returns this error when the homepage responds with a non-200 HTTP status. The library treats any non-OK status as fatal for formhash extraction since the HTML will not contain the expected form.
Solutions
- Log resp.StatusCode and set a browser-like User-Agent in setRequestHeaders
- Back off and retry later if rate-limited (429)
- Check the response body for Cloudflare/captcha challenges and consider cookie warming
- Verify the site is healthy (check in a browser)
- Follow redirects properly (ensure client.CheckRedirect is default)
Example fix
// before
req.Header.Set("User-Agent", "go-http-client")
// after
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36") Defensive patterns
Strategy: fallback
Validate before calling
resp, err := http.Get(BaseURL)
if err == nil && resp.StatusCode != 200 {
// site is returning errors/blocked; skip search or alert
} Try / catch
if err != nil && strings.Contains(err.Error(), "首页请求返回状态码") {
var statusErr interface{ Error() string }
_ = statusErr
// inspect status code in message: back off on 429, alert on 5xx
} Prevention
- Set a browser-like User-Agent to avoid bot blocking
- Throttle request rate to avoid 429s
- Detect and handle challenge pages (Cloudflare etc.)
- Alert on persistent 5xx — site outage
When it happens
Trigger: client.Do succeeds but resp.StatusCode != 200 — e.g., 403 (bot blocking), 429 (rate limited), 5xx (server error), 30x handled oddly, or a challenge page.
Common situations: Site WAF/Cloudflare blocking the default User-Agent, IP rate limiting after frequent searches, temporary server outage, or being redirected to a login/captcha page.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/89bd7512fb45f435.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/qupanshe/qupanshe.go:174
resp, err := client.Do(req)
if err != nil {
return "", fmt.Errorf("GET请求失败: %w", err)
}
defer resp.Body.Close()
// 调试:显示从首页获取的cookies
if DebugLog && client.Jar != nil {
if u, _ := url.Parse(BaseURL); u != nil {
cookies := client.Jar.Cookies(u)
fmt.Printf("[qupanshe] 从首页获取到 %d 个cookies:\n", len(cookies))
for i, cookie := range cookies {
fmt.Printf(" Cookie[%d]: %s=%s\n", i, cookie.Name, cookie.Value)
}
}
}
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("首页请求返回状态码: %d", resp.StatusCode)
}
// 处理可能的gzip压缩
var reader io.Reader = resp.Body
if resp.Header.Get("Content-Encoding") == "gzip" {
gzipReader, err := gzip.NewReader(resp.Body)
if err != nil {
return "", fmt.Errorf("创建gzip读取器失败: %w", err)
}
defer gzipReader.Close()
reader = gzipReader
}
// 解析HTML
doc, err := goquery.NewDocumentFromReader(reader)
if err != nil {
return "", fmt.Errorf("解析HTML失败: %w", err)
}View on GitHub (pinned to beaa561337)