fish2018/pansou · error

[ ] 解码搜索结果失败

Error message

[%s] 解码搜索结果失败: %w

What it means

fetchSearch wraps an error from decodeGB18030(body) — converting the site's GB18030-encoded HTML to UTF-8 failed. This is a plugin-local charset conversion; it fires only if the decode helper cannot transcode the bytes, typically because the payload is not actually GB18030 (e.g. a compressed, blank, or binary anti-bot page replaced the expected HTML).

Solutions

  1. Check the wrapped %w error to see what the decoder rejected, and dump the first bytes of body (hex) to confirm whether it's GB18030 HTML or a challenge/binary payload.
  2. If Content-Encoding is gzip, ensure the transport decompresses (DisableCompression=false) or decompress before decoding.
  3. Inspect the live page's charset meta tag with curl and update decodeGB18030 or use golang.org/x/net/html/charset auto-detection.
  4. Handle an empty body explicitly before decoding to give a clearer message.

Example fix

// before
decoded, err := decodeGB18030(body)
if err != nil {
    return nil, fmt.Errorf("[%s] 解码搜索结果失败: %w", p.Name(), err)
}
// after
if len(body) == 0 {
    return nil, fmt.Errorf("[%s] 搜索结果为空", p.Name())
}
decoded, err := decodeGB18030(body)
if err != nil {
    return nil, fmt.Errorf("[%s] 解码搜索结果失败: %w", p.Name(), err)
}
Defensive patterns

Strategy: validation

Validate before calling

// 解码前预检响应体
if len(body) == 0 {
    return fmt.Errorf("响应体为空")
}
if ct := ""; resp.Header.Get("Content-Encoding") == "gzip" {
    return fmt.Errorf("响应未解压, 解码前需 gzip 解压")
}

Prevention

When it happens

Trigger: decodeGB18030 returns err: the response body is gzip/deflate-compressed but the request didn't request/accept decompression, the body is empty or binary garbage from a WAF challenge page, or the site switched to UTF-8 and the decoder rejects/produces invalid output (depending on the helper's implementation).

Common situations: Anti-bot returns an encoded challenge instead of HTML; Content-Encoding (gzip) is set but the body wasn't decompressed before decoding; the site silently migrated its encoding to UTF-8, breaking the assumed GB18030 input.

Related errors


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

Appendix: source

Thrown at plugin/5266ys/5266ys.go:194

		return nil, fmt.Errorf("[%s] 创建搜索请求失败: %w", p.Name(), err)
	}
	setHeaders(req, baseURL+"/")
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	resp, err := client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("[%s] 搜索请求失败: %w", p.Name(), err)
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("[%s] 搜索请求返回 HTTP %d", p.Name(), resp.StatusCode)
	}
	body, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
	if err != nil {
		return nil, fmt.Errorf("[%s] 读取搜索结果失败: %w", p.Name(), err)
	}
	decoded, err := decodeGB18030(body)
	if err != nil {
		return nil, fmt.Errorf("[%s] 解码搜索结果失败: %w", p.Name(), err)
	}
	doc, err := goquery.NewDocumentFromReader(strings.NewReader(decoded))
	if err != nil {
		return nil, fmt.Errorf("[%s] 解析搜索结果失败: %w", p.Name(), err)
	}
	return doc, nil
}

func (p *Plugin) fetchDetail(client *http.Client, detailURL string) ([]magnetItem, string, string) {
	ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
	defer cancel()
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, detailURL, nil)
	if err != nil {
		return nil, "", ""
	}
	setHeaders(req, baseURL+"/")
	resp, err := client.Do(req)
	if err != nil {

View on GitHub (pinned to beaa561337)