fish2018/pansou · error
创建请求失败
Error message
创建请求失败: %w
What it means
hdr4k's doSearch wraps errors from http.NewRequest as 创建请求失败. Building a POST request to the 4KHDR search endpoint failed — with a strings.NewReader body this essentially only happens if SearchURL is not a parseable absolute URL.
Solutions
- Print SearchURL and fix any malformed characters or missing scheme
- Validate with url.Parse(SearchURL) at plugin init so misconfiguration fails fast
- URL-encode any dynamic parts of the URL instead of concatenating raw text
- Restore the correct constant if it was accidentally changed
Example fix
// before
req, err := http.NewRequest("POST", SearchURL, strings.NewReader(data.Encode()))
if err != nil {
return nil, fmt.Errorf("创建请求失败: %w", err)
}
// after
if _, err := url.Parse(SearchURL); err != nil {
return nil, fmt.Errorf("配置的 SearchURL 无效 %q: %w", SearchURL, err)
}
req, err := http.NewRequest("POST", SearchURL, strings.NewReader(data.Encode()))
if err != nil {
return nil, fmt.Errorf("创建请求失败: %w", err)
} Defensive patterns
Strategy: validation
Validate before calling
// Go: fail fast on a misconfigured SearchURL
if SearchURL == "" {
return nil, fmt.Errorf("SearchURL is not configured")
}
if _, err := url.Parse(SearchURL); err != nil {
return nil, fmt.Errorf("SearchURL invalid: %w", err)
} Try / catch
req, err := http.NewRequest("POST", SearchURL, strings.NewReader(data.Encode()))
if err != nil {
return nil, fmt.Errorf("创建请求失败: %w (SearchURL=%q)", err, SearchURL)
} Prevention
- Validate configured URLs once at startup, not per request
- Keep URL constants free of whitespace/typos
- Add a startup smoke test that builds each plugin's request
When it happens
Trigger: http.NewRequest("POST", SearchURL, ...) errors because SearchURL is empty, malformed, or contains invalid characters (spaces, unencoded CJK) — e.g. a misconfigured or corrupted constant.
Common situations: BaseURL/SearchURL constant edited incorrectly; config value with whitespace or wrong scheme; build-time templating producing an empty URL.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/e3a06a13c15fbff3.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/hdr4k/hdr4k.go:143
// 处理ext参数
searchKeyword := keyword
if ext != nil {
// 使用类型断言安全地获取参数
if titleEn, ok := ext["title_en"].(string); ok && titleEn != "" {
// 使用英文标题替换关键词
searchKeyword = titleEn
}
}
// 构建POST请求数据
data := url.Values{}
data.Set("srchtxt", searchKeyword)
data.Set("searchsubmit", "yes")
// 发送POST请求
req, err := http.NewRequest("POST", SearchURL, strings.NewReader(data.Encode()))
if err != nil {
return nil, fmt.Errorf("创建请求失败: %w", err)
}
// 设置请求头
req.Header.Set("User-Agent", getRandomUA())
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("Referer", "https://www.4khdr.cn/")
// 发送请求(带重试)
resp, err := p.doRequestWithRetry(client, req, MaxRetries)
if err != nil {
return nil, fmt.Errorf("请求失败: %w", err)
}
defer resp.Body.Close()
// 解析HTML
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
return nil, fmt.Errorf("解析HTML失败: %w", err)View on GitHub (pinned to beaa561337)