fish2018/pansou · error

[ ] 搜索 API 返回状态码

Error message

[%s] 搜索 API 返回状态码: %d

What it means

After the API request succeeds at transport level, searchImpl requires HTTP 200; any other status triggers the searchWeb HTML fallback with this error carrying the status code. It indicates the API responded but rejected or redirected the request.

Solutions

  1. Log the status code and response body snippet to identify the cause (403 vs 429 vs 5xx)
  2. Update User-Agent/Referer/Accept headers to mimic a current browser
  3. Slow down request rate or add backoff if 429
  4. Update the API base URL if the site migrated domains

Example fix

// before
if resp.StatusCode != 200 {
    return p.searchWeb(client, keyword, fmt.Errorf("[%s] 搜索 API 返回状态码: %d", p.Name(), resp.StatusCode))
}
// after
if resp.StatusCode != http.StatusOK {
    if resp.StatusCode == http.StatusTooManyRequests {
        time.Sleep(2 * time.Second)
    }
    return p.searchWeb(client, keyword, fmt.Errorf("[%s] 搜索 API 返回状态码: %d", p.Name(), resp.StatusCode))
}
Defensive patterns

Strategy: retry

Validate before calling

// can't pre-validate server status; add preflight rate limiting
limiter.Wait(ctx) // ensure request rate stays under upstream limits

Try / catch

results, err := plugin.Search(keyword)
if err != nil {
    var statusErr *statusError // if plugin exposes typed status errors
    if errors.As(err, &statusErr) && statusErr.Code == 429 {
        time.Sleep(time.Until(time.Now().Add(30 * time.Second)))
        results, err = plugin.Search(keyword)
    }
}

Prevention

When it happens

Trigger: resp.StatusCode != 200 — e.g. 403 from anti-bot protection, 404 after a domain migration, 429 rate limit, 5xx upstream outage.

Common situations: Cloudflare/WAF blocking non-browser requests, stale Referer/User-Agent headers after site update, hitting rate limits under heavy scanning.

Related errors


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

Appendix: source

Thrown at plugin/feikuai/feikuai.go:133

	}

	// 设置请求头
	req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
	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("Referer", "https://feikuai.tv/")

	// 发送请求(带重试)
	resp, err := p.doRequestWithRetry(req, client)
	if err != nil {
		return p.searchWeb(client, keyword, fmt.Errorf("[%s] 搜索 API 请求失败: %w", p.Name(), err))
	}
	defer resp.Body.Close()

	// 检查状态码
	if resp.StatusCode != 200 {
		return p.searchWeb(client, keyword, fmt.Errorf("[%s] 搜索 API 返回状态码: %d", p.Name(), resp.StatusCode))
	}

	// 读取并解析JSON响应
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return p.searchWeb(client, keyword, fmt.Errorf("[%s] 读取 API 响应失败: %w", p.Name(), err))
	}

	var apiResp FeikuaiAPIResponse
	if err := json.Unmarshal(body, &apiResp); err != nil {
		return p.searchWeb(client, keyword, fmt.Errorf("[%s] API JSON 解析失败: %w", p.Name(), err))
	}

	// 检查API响应状态
	if apiResp.Code != 0 {
		return p.searchWeb(client, keyword, fmt.Errorf("[%s] API 返回错误: %s (code: %d)", p.Name(), apiResp.Msg, apiResp.Code))
	}

View on GitHub (pinned to beaa561337)