fish2018/pansou · error

create request failed

Error message

create request failed (page %d): %w

What it means

After marshaling, the plugin builds the POST with http.NewRequest. Failure means the request could not be constructed — almost always a malformed apiURL (unparseable URL) since the body is a valid bytes.Buffer.

Solutions

  1. Log the wrapped error and print apiURL to spot invalid characters or a missing scheme
  2. Use url.Parse(apiURL) beforehand to validate the endpoint URL
  3. Build the URL with url.Values / url.Build to escape the keyword properly (url.QueryEscape)
  4. Fix the API endpoint constant/config value that produces the malformed URL

Example fix

// before
req, err := http.NewRequest("POST", apiURL, bytes.NewBuffer(jsonData))
if err != nil {
	errChan <- fmt.Errorf("create request failed (page %d): %w", pageNum, err)
	return
}
// after
if _, perr := url.Parse(apiURL); perr != nil {
	errChan <- fmt.Errorf("invalid api URL %q: %w", apiURL, perr)
	return
}
req, err := http.NewRequest("POST", apiURL, bytes.NewBuffer(jsonData))
if err != nil {
	errChan <- fmt.Errorf("create request failed (page %d): %w", pageNum, err)
	return
}
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.Parse(apiURL)
if err != nil || u.Scheme == "" || u.Host == "" {
	// endpoint URL invalid; fix config before calling the plugin
}

Type guard

func isValidURL(s string) bool {
	u, err := url.Parse(s)
	return err == nil && (u.Scheme == "http" || u.Scheme == "https") && u.Host != ""
}

Try / catch

if err != nil && strings.Contains(err.Error(), "create request failed") {
	log.Printf("bad endpoint URL: %v", err) // fix the apiURL constant/config
}

Prevention

When it happens

Trigger: http.NewRequest("POST", apiURL, bytes.NewBuffer(jsonData)) returns an error for a given page — typically apiURL contains invalid characters, spaces, or an unsupported scheme.

Common situations: API endpoint constant containing whitespace/fullwidth characters or a wrong scheme (missing http://), URL built by string concatenation with unescaped keyword, misconfigured base URL in plugin config.

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/449c4614504096db. Report an issue: GitHub.

Appendix: source

Thrown at plugin/hunhepan/hunhepan.go:211

				"adv_params": map[string]interface{}{
					"wechat_pwd": "",
					"platform":   "pc",
				},
			}

			jsonData, err := json.Marshal(reqBody)
			if err != nil {
				debugLog("序列化请求失败 (page %d): %v", pageNum, err)
				errChan <- fmt.Errorf("marshal request failed (page %d): %w", pageNum, err)
				return
			}

			debugLog("发送请求到 %s (page %d): %s", apiURL, pageNum, string(jsonData))

			req, err := http.NewRequest("POST", apiURL, bytes.NewBuffer(jsonData))
			if err != nil {
				debugLog("创建请求失败 (page %d): %v", pageNum, err)
				errChan <- fmt.Errorf("create request failed (page %d): %w", pageNum, err)
				return
			}

			req.Header.Set("Content-Type", "application/json")
			req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
			req.Header.Set("Accept", "application/json, text/plain, */*")
			req.Header.Set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")

			// 根据不同的API设置不同的Referer
			if strings.Contains(apiURL, "qkpanso.com") {
				req.Header.Set("Referer", "https://qkpanso.com/search")
			} else if strings.Contains(apiURL, "kuake8.com") {
				req.Header.Set("Referer", "https://kuake8.com/search")
			} else if strings.Contains(apiURL, "hunhepan.com") {
				req.Header.Set("Referer", "https://hunhepan.com/search")
			} else if strings.Contains(apiURL, "misoso.cc") {
				req.Header.Set("Referer", "https://www.misoso.cc/search")
				req.Header.Set("Origin", "https://www.misoso.cc")

View on GitHub (pinned to beaa561337)