fish2018/pansou · error

搜索响应状态码异常

Error message

搜索响应状态码异常: %d

What it means

searchImpl in the leijing plugin checks the HTTP status after the search request and rejects anything other than 200 OK. This means the server responded but indicated the request was not successful (redirect to captcha, 403 anti-bot, 404 after site restructure, 5xx outage).

Solutions

  1. Log the status code and body snippet to identify what the server actually returned
  2. Add anti-bot headers (realistic User-Agent, Referer, Cookie) to pass WAF checks
  3. Handle 429 with backoff/retry; handle redirects by updating the URL constant
  4. Verify the search URL path still exists on the site and update if restructured
  5. Route through a proxy or reduce request rate if the site throttles by IP

Example fix

// before
return nil, fmt.Errorf("搜索响应状态码异常: %d", resp.StatusCode)
// after
body, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
return nil, fmt.Errorf("搜索响应状态码异常: %d, body: %s", resp.StatusCode, body)
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight: confirm the search endpoint still returns 200
resp, err := client.Head(searchURL)
if err != nil || resp.StatusCode != http.StatusOK {
    log.Printf("leijing endpoint unhealthy: status=%v err=%v", resp, err)
}

Try / catch

results, err := plugin.Search(ctx, keyword)
if err != nil {
    var statusErr interface{ Error() string }
    if strings.Contains(err.Error(), "搜索响应状态码异常") {
        // extract status, back off for 429/5xx, or switch mirror
        return alternateSearch(keyword)
    }
    return err
}

Prevention

When it happens

Trigger: doRequest succeeded but resp.StatusCode != http.StatusOK for the search URL — e.g. the site returns 403 for bot-like traffic, 301/302 to a login/captcha page (if redirects were not followed), or 503 during maintenance.

Common situations: Anti-bot protection (Cloudflare/WAF) challenging the crawler; site restructured and the search path now 404s; rate limiting returning 429; CDN serving 5xx errors.

Related errors


AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07). Data as JSON: /api/errors/21a174a1827f1d5c. Report an issue: GitHub.

Appendix: source

Thrown at plugin/leijing/leijing.go:137

// searchImpl 实际的搜索实现
func (p *LeijingPlugin) searchImpl(client *http.Client, keyword string, ext map[string]interface{}) ([]model.SearchResult, error) {
	searchURL := fmt.Sprintf("%s%s?keyword=%s", BaseURL, SearchPath, url.QueryEscape(keyword))
	
	if p.debugMode {
		log.Printf("[Leijing] 开始搜索: %s", keyword)
		log.Printf("[Leijing] 搜索URL: %s", searchURL)
	}
	
	// 发送搜索请求
	resp, err := p.doRequest(client, searchURL, BaseURL)
	if err != nil {
		return nil, fmt.Errorf("发送搜索请求失败: %w", err)
	}
	defer resp.Body.Close()
	
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("搜索响应状态码异常: %d", resp.StatusCode)
	}
	
	// 处理响应体(可能是gzip压缩的)
	reader, err := p.getResponseReader(resp)
	if err != nil {
		return nil, err
	}
	
	// 解析HTML
	doc, err := goquery.NewDocumentFromReader(reader)
	if err != nil {
		return nil, fmt.Errorf("解析HTML失败: %w", err)
	}
	
	// 提取搜索结果
	results := p.extractSearchResults(doc, keyword)
	
	if p.debugMode {

View on GitHub (pinned to beaa561337)