fish2018/pansou · error

状态码

Error message

状态码 %d

What it means

This internal error is produced by Dy4kPlugin.doRequestWithRetry when the server responds with a non-acceptable HTTP status code; the status code is recorded as lastErr. It is not returned directly — after all retries are exhausted it is wrapped by error 123. It means the 4KDY site repeatedly answered with an error status (403, 429, 5xx, etc.) across every retry attempt.

Solutions

  1. Check the debug log's response body preview to identify which status and page the server returned
  2. Back off and retry later if the status is 429 (rate limiting)
  3. Rotate the User-Agent (getRandomUA) or route through a different IP/proxy if 403
  4. Verify the site is up and the domain hasn't changed (5xx / NXIO cases)

Example fix

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

Strategy: retry

Validate before calling

resp, err := client.Get(probeURL)
if err == nil && resp.StatusCode == http.StatusOK { /* site reachable, proceed */ }

Try / catch

body, err := doRequestWithRetry(client, url)
if err != nil {
    if strings.Contains(err.Error(), "状态码 429") {
        time.Sleep(rateLimitBackoff) // honor rate limiting
    }
    return err
}

Prevention

When it happens

Trigger: searchPage -> doRequestWithRetry when every attempt receives a rejected status code (e.g., 403 blocked, 429 rate-limited, 500/502 server error) and the response status check fails on all retries.

Common situations: IP is blocked or rate-limited by the site's anti-scraping defenses; User-Agent flagged; site temporarily down (5xx); geo-blocking; expired domain serving error pages.

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/abb9dac54192b57d. Report an issue: GitHub.

Appendix: source

Thrown at plugin/dy4k/dy4k.go:1056

			return resp, nil
		}

		debugPrintf("❌ [Dy4k DEBUG] 第 %d 次尝试状态码异常: %d\n", i+1, resp.StatusCode)

		// 读取响应体以便调试
		if resp.Body != nil {
			bodyBytes, readErr := io.ReadAll(resp.Body)
			resp.Body.Close()
			if readErr == nil && len(bodyBytes) > 0 {
				bodyPreview := string(bodyBytes)
				if len(bodyPreview) > 200 {
					bodyPreview = bodyPreview[:200] + "..."
				}
				debugPrintf("🔧 [Dy4k DEBUG] 响应体预览: %s\n", bodyPreview)
			}
		}

		lastErr = fmt.Errorf("状态码 %d", resp.StatusCode)
	}

	debugPrintf("❌ [Dy4k DEBUG] 所有重试都失败了!\n")
	return nil, fmt.Errorf("重试 %d 次后仍然失败: %w", maxRetries, lastErr)
}

// getRandomUA 获取随机User-Agent
func getRandomUA() string {
	userAgents := []string{
		"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
		"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
		"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
		"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15",
		"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0",
		"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
		"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0",
		"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
	}

View on GitHub (pinned to beaa561337)