fish2018/pansou · error

[ ] token请求HTTP状态错误

Error message

[%s] token请求HTTP状态错误: %d

What it means

getToken rejects the token page response when its HTTP status is not 200. The plugin strictly requires a 200 HTML page from which to scrape DToken; any redirect landing on an error page, anti-bot challenge, or 5xx triggers this error. The status code is embedded in the message for diagnosis.

Solutions

  1. Log the status code and response body snippet to identify what the server actually returned (challenge page vs error)
  2. Check for IP bans/rate limits; reduce request frequency or rotate proxy/IP
  3. Update the User-Agent and browser-like headers in getToken to a current browser value
  4. Handle redirects/captcha endpoints explicitly if the site introduced an anti-bot interstitial

Example fix

null
Defensive patterns

Strategy: retry

Try / catch

var httpErr *HTTPStatusError
if errors.As(err, &httpErr) && (httpErr.Code == 403 || httpErr.Code == 429) {
    time.Sleep(backoff)
    return retryWithFreshIP()
}

Prevention

When it happens

Trigger: doRequestWithRetry succeeded but resp.StatusCode != 200 (e.g. 403 from WAF/anti-bot, 302 followed to a captcha page, 502/503 from an overloaded upstream).

Common situations: Site upgraded anti-bot measures (Cloudflare challenge page); IP rate-limited or banned; region blocking returning 403; upstream outage returning 502/503; User-Agent header blacklisted.

Related errors


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

Appendix: source

Thrown at plugin/xys/xys.go:168

	}

	// 设置完整的请求头
	req.Header.Set("User-Agent", UserAgent)
	req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
	req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
	req.Header.Set("Connection", "keep-alive")
	req.Header.Set("Upgrade-Insecure-Requests", "1")
	req.Header.Set("Cache-Control", "max-age=0")
	req.Header.Set("Referer", BaseURL+"/")

	resp, err := p.doRequestWithRetry(req, client)
	if err != nil {
		return "", fmt.Errorf("[%s] token请求失败: %w", p.Name(), err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		return "", fmt.Errorf("[%s] token请求HTTP状态错误: %d", p.Name(), resp.StatusCode)
	}

	// 解析HTML提取token
	doc, err := goquery.NewDocumentFromReader(resp.Body)
	if err != nil {
		return "", fmt.Errorf("[%s] 解析token页面HTML失败: %w", p.Name(), err)
	}

	// 查找script标签中的DToken定义
	var token string
	doc.Find("script").Each(func(i int, s *goquery.Selection) {
		scriptContent := s.Text()
		if strings.Contains(scriptContent, "DToken") {
			// 使用正则表达式提取token
			re := regexp.MustCompile(`const\s+DToken\s*=\s*"([^"]+)"`)
			matches := re.FindStringSubmatch(scriptContent)
			if len(matches) > 1 {
				token = matches[1]

View on GitHub (pinned to beaa561337)