fish2018/pansou · error

HTTP状态码

Error message

HTTP状态码: %d

What it means

doRequestWithRetry retries the HTTP request; on each attempt with successful transport but non-200 status, it closes the body and records 'HTTP状态码: %d' as lastErr, then retries. If all attempts return non-200, this is the error surfaced to the caller. It means the server responded but rejected the request.

Solutions

  1. Log/inspect the status code: 403→anti-bot (add headers/cookies), 429→slow down, 5xx→retry later
  2. Increase sleep between retries for 429 responses
  3. Rotate mirror domains on repeated non-200
  4. Add browser-like headers and cookies to defeat simple anti-bot checks

Example fix

// before
lastErr = fmt.Errorf("HTTP状态码: %d", resp.StatusCode)
// after
lastErr = fmt.Errorf("HTTP状态码: %d", resp.StatusCode)
if resp.StatusCode == http.StatusTooManyRequests {
    time.Sleep(2 * time.Second) // honor rate limit before next retry
}
Defensive patterns

Strategy: retry

Try / catch

_, err := plugin.Search(ctx, q)
if strings.Contains(err.Error(), "HTTP状态码: 429") {
    time.Sleep(time.Duration(retryAfter) * time.Second)
    // retry with lower rate
} else if strings.Contains(err.Error(), "HTTP状态码: 40") {
    // switch mirror / fix credentials — retrying won't help
}

Prevention

When it happens

Trigger: searchImpl calling doRequestWithRetry when the wanou endpoint persistently returns 403 (anti-bot), 429 (rate limited), 5xx, or 404 across all retries.

Common situations: Datacenter IP blocked by the mirror; too-frequent requests triggering 429; the site under maintenance (503); old domain now serving 404.

Related errors


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

Appendix: source

Thrown at plugin/wanou/wanou.go:446

	if len(matches) > 1 {
		return matches[1]
	}
	return ""
}

// doRequestWithRetry 带重试的HTTP请求(优化JSON API的重试策略)
func (p *WanouAsyncPlugin) doRequestWithRetry(req *http.Request, client *http.Client) (*http.Response, error) {
	maxRetries := 2  // 对于JSON API减少重试次数
	var lastErr error
	
	for i := 0; i < maxRetries; i++ {
		resp, err := client.Do(req)
		if err == nil {
			if resp.StatusCode == http.StatusOK {
				return resp, nil
			}
			resp.Body.Close()
			lastErr = fmt.Errorf("HTTP状态码: %d", resp.StatusCode)
		} else {
			lastErr = err
		}
		
		// JSON API快速重试:只等待很短时间
		if i < maxRetries-1 {
			time.Sleep(100 * time.Millisecond) // 从秒级改为100毫秒
		}
	}
	
	return nil, fmt.Errorf("[%s] 请求失败,重试%d次后仍失败: %w", p.Name(), maxRetries, lastErr)
}

// GetPerformanceStats 获取性能统计信息
func (p *WanouAsyncPlugin) GetPerformanceStats() map[string]interface{} {
	totalRequests := atomic.LoadInt64(&searchRequests)
	totalTime := atomic.LoadInt64(&totalSearchTime)
	

View on GitHub (pinned to beaa561337)