fish2018/pansou · error
创建验证请求失败
Error message
创建验证请求失败: %w
What it means
solveVerification builds a GET http.Request for the verification endpoint with http.NewRequestWithContext. If request construction fails (invalid method/URL), the error is wrapped as 创建验证请求失败. This indicates the constructed verifyURL is not a valid absolute HTTP URL.
Solutions
- Ensure the pageURL passed to getDetailInfo/searchSuggest includes an absolute scheme (https://)
- Log verifyURL before request creation to spot missing scheme/host
- Fallback to "https" if parsedPage.Scheme is empty
Example fix
// before
verifyURL := (&url.URL{Scheme: parsedPage.Scheme, Host: parsedPage.Host, Path: endpointPath}).String()
// after
scheme := parsedPage.Scheme
if scheme == "" {
scheme = "https"
}
verifyURL := (&url.URL{Scheme: scheme, Host: parsedPage.Host, Path: endpointPath}).String() Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(rawURL)
if err != nil || u.Scheme == "" || u.Host == "" {
return fmt.Errorf("url must be absolute: %w", err)
} Try / catch
info, err := plugin.GetDetailInfo(ctx, url)
if err != nil && strings.Contains(err.Error(), "创建验证请求失败") {
log.Printf("verification request could not be built for %s: %v", url, err)
} Prevention
- Always pass absolute http(s) URLs into the plugin
- Avoid building URLs by string concatenation; use url.URL structs
- If using scheme-relative URLs, default the scheme to https before calling
When it happens
Trigger: http.NewRequestWithContext returns an error — typically because parsedPage had an empty/invalid Scheme or Host so the reconstructed verifyURL is not absolute (e.g. missing scheme).
Common situations: Page URL was scheme-relative (//host/path) so parsedPage.Scheme is empty; pageURL had no host (e.g. a relative path leaked in); programmatic URL reconstruction dropped the scheme.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/cdf5fd78f5ed6169.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/qiwei/qiwei.go:389
if endpointMatch := verificationEndpointRegex.FindStringSubmatch(jsBody); len(endpointMatch) > 1 {
endpointPath = "/" + endpointMatch[1]
}
parsedPage, err := url.Parse(pageURL)
if err != nil {
return fmt.Errorf("验证页面地址无效: %w", err)
}
verifyURL := (&url.URL{Scheme: parsedPage.Scheme, Host: parsedPage.Host, Path: endpointPath}).String()
query := url.Values{}
query.Set("type", typeMatch[1])
query.Set("key", keyMatch[1])
query.Set("value", encodedValue)
verifyURL += "?" + query.Encode()
ctx, cancel := context.WithTimeout(context.Background(), detailTimeout)
defer cancel()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, verifyURL, nil)
if err != nil {
return fmt.Errorf("创建验证请求失败: %w", err)
}
p.setHeaders(req, pageURL)
req.Header.Set("X-Requested-With", "XMLHttpRequest")
resp, err := p.doRequestWithRetry(req, client)
if err != nil {
return fmt.Errorf("提交验证失败: %w", err)
}
defer resp.Body.Close()
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("读取验证响应失败: %w", err)
}
if isVerifyPage(string(responseBody)) {
return fmt.Errorf("站点未接受验证参数")
}
return nil
}
View on GitHub (pinned to beaa561337)