fish2018/pansou · error
搜索请求失败
Error message
搜索请求失败: %w
What it means
xb6v's searchImpl POSTs the search form through p.doRequest using a no-redirect client (CheckRedirect returns http.ErrUseLastResponse) and wraps any transport failure as this error. It fires when the POST itself fails — DNS, connect, TLS, or timeout — before any response is available.
Solutions
- Unwrap the error and check for DNS errors (e.g. 'no such host') — if present, the site domain changed and currentBase must be updated (run the plugin's base-discovery/fallback logic if available).
- Verify network egress/DNS from the runtime environment (curl the search URL).
- Confirm the search URL is built correctly (log searchURL) and includes no stale protocol/host.
- Increase timeouts / enable retries in doRequest if the site is slow.
- Configure proxy support if the site is blocked from your region.
Example fix
// before
resp, err := p.doRequest(noRedirectClient, "POST", searchURL, postData, p.currentBase)
if err != nil {
return nil, fmt.Errorf("搜索请求失败: %w", err)
}
// after
resp, err := p.doRequest(noRedirectClient, "POST", searchURL, postData, p.currentBase)
if err != nil {
if strings.Contains(err.Error(), "no such host") {
if rerr := p.refreshBaseURL(); rerr == nil {
return p.searchImpl(keyword)
}
}
return nil, fmt.Errorf("搜索请求失败: %w", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
// verify the configured base is reachable before searching
resp, err := http.Get(p.currentBase)
if err != nil { /* refresh base URL or report site down */ } Try / catch
results, err := p.search(keyword)
if err != nil && strings.Contains(err.Error(), "搜索请求失败") {
if strings.Contains(err.Error(), "no such host") {
// domain likely changed; attempt base-url refresh
}
return nil, err
} Prevention
- Keep base-URL discovery/fallback logic to survive domain changes
- Check DNS egress from the deployment environment
- Log the full searchURL when requests fail
- Add proxy support for blocked regions
When it happens
Trigger: p.doRequest(noRedirectClient, "POST", searchURL, postData, p.currentBase) returns an error: searchURL (currentBase + SearchPath) unreachable, domain changed, TLS failure, connection refused, or request timeout. Note it is not triggered by non-2xx responses — those are returned normally.
Common situations: The xb6v site changing its domain (p.currentBase stale) so the host no longer resolves; the site blocking the plugin's requests entirely; no network egress from the deployment environment; timeouts on a slow/overloaded site.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/7193021536e97ae3.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/xb6v/xb6v.go:182
if p.debugMode {
log.Printf("[Xb6v] 开始搜索: %s (原始: %s)", keyword, originalKeyword)
}
// 第一步:POST搜索请求
searchURL := p.currentBase + SearchPath
postData := fmt.Sprintf("show=title&tempid=1&tbname=article&mid=1&dopost=search&submit=&keyboard=%s", url.QueryEscape(keyword))
// 创建不自动重定向的客户端
noRedirectClient := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
resp, err := p.doRequest(noRedirectClient, "POST", searchURL, postData, p.currentBase)
if err != nil {
return nil, fmt.Errorf("搜索请求失败: %w", err)
}
defer resp.Body.Close()
if p.debugMode {
log.Printf("[Xb6v] POST响应状态码: %d", resp.StatusCode)
}
// 获取重定向的location
location := resp.Header.Get("Location")
if p.debugMode {
log.Printf("[Xb6v] Location头: '%s'", location)
}
// 如果没有Location头,可能需要从响应体中解析
if location == "" {
if p.debugMode {
log.Printf("[Xb6v] 未找到Location头,尝试解析响应体")
}View on GitHub (pinned to beaa561337)