fish2018/pansou · error

重定向响应中没有Location头部

Error message

重定向响应中没有Location头部

What it means

In getSearchID, the plugin expects the search endpoint to respond with a 302 redirect whose Location header carries the searchid. When the status code is 302 but the Location header is empty or missing, this error is thrown. It means the upstream server redirected without telling the client where to go, so the searchid cannot be obtained.

Solutions

  1. Verify the upstream endpoint still returns a proper 302 with a Location header (curl -i on the search URL).
  2. Check whether an anti-bot mechanism is intercepting the request; set realistic request headers (User-Agent, Referer, cookies) in the plugin's HTTP client.
  3. Bypass or reconfigure any proxy between the client and the upstream that may strip the Location header.
  4. If the site changed APIs, update the getSearchID flow to the new redirect/response scheme.

Example fix

// before
location := resp.Header.Get("Location")
if location == "" {
    return "", fmt.Errorf("重定向响应中没有Location头部")
}
// after (log status and headers for diagnosis)
location := resp.Header.Get("Location")
if location == "" {
    return "", fmt.Errorf("重定向响应中没有Location头部 (status=%d, ct=%s)", resp.StatusCode, resp.Header.Get("Content-Type"))
}
Defensive patterns

Strategy: try-catch

Try / catch

id, err := client.SearchWithResult(ctx, keyword)
if err != nil {
    if strings.Contains(err.Error(), "没有Location头部") {
        // upstream redirect malformed: back off and retry later, or fall back to another plugin
    } else {
        return err
    }
}

Prevention

When it happens

Trigger: Calling SearchWithResult when the upstream server returns HTTP 302 but omits the Location header — e.g. a broken redirect, an anti-bot interstitial responding 302 without a target, or a proxy stripping the Location header.

Common situations: Upstream site changed its redirect behavior or now serves an anti-bot/challenge page; a corporate or transparent proxy strips hop-by-hop headers; CDN misconfiguration returns 302 with no Location.

Related errors


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

Appendix: source

Thrown at plugin/clxiong/clxiong.go:163

		if i < MaxRetries-1 {
			time.Sleep(RetryDelay)
		}
	}

	if lastErr != nil {
		return "", lastErr
	}
	defer resp.Body.Close()

	// 检查重定向响应
	if resp.StatusCode != 302 && resp.StatusCode != 301 {
		return "", fmt.Errorf("期望302重定向,但得到状态码: %d", resp.StatusCode)
	}

	// 从Location头部提取searchid
	location := resp.Header.Get("Location")
	if location == "" {
		return "", fmt.Errorf("重定向响应中没有Location头部")
	}

	// 解析searchid
	searchID := p.extractSearchIDFromLocation(location)
	if searchID == "" {
		return "", fmt.Errorf("无法从Location中提取searchid: %s", location)
	}

	if p.debugMode {
		log.Printf("[CLXIONG] 获取到searchid: %s", searchID)
	}

	return searchID, nil
}

// extractSearchIDFromLocation 从Location头部提取searchid
func (p *ClxiongPlugin) extractSearchIDFromLocation(location string) string {
	// location格式: "result/?searchid=7549"

View on GitHub (pinned to beaa561337)