fish2018/pansou · error

创建初始请求失败

Error message

创建初始请求失败: %w

What it means

Returned by searchPage when http.NewRequest (or the initial search request construction for the first page fetch) fails. It fires before any network I/O: the cause is a malformed or unparseable initial URL built from the keyword, or an invalid method/ctx combination, so the per-page scrape never starts.

Solutions

  1. 校验 currentBaseURL 与 URL 拼接结果
  2. 对关键词做 QueryEscape 转义
  3. 补充构造失败日志
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at plugin/panwiki/panwiki.go:164 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at plugin/panwiki/panwiki.go:164

	if p.debugMode {
		log.Printf("[Panwiki] 关键词过滤完成,过滤前: %d,过滤后: %d", len(allResults), len(filteredResults))
		for i, result := range filteredResults {
			log.Printf("[Panwiki] 最终结果%d: MessageID=%s, UniqueID=%s, 标题=%s, 链接数=%d", i+1, result.MessageID, result.UniqueID, result.Title, len(result.Links))
		}
		log.Printf("[Panwiki] 🚀 插件返回结果总数: %d", len(filteredResults))
	}

	return filteredResults, nil
}

// searchPage 搜索指定页面
func (p *PanwikiPlugin) searchPage(client *http.Client, keyword string, page int) ([]model.SearchResult, error) {
	// Step 1: 发起初始搜索请求获取重定向URL
	initialURL := p.getSearchURL(keyword, page)
	
	req, err := http.NewRequest("GET", initialURL, nil)
	if err != nil {
		return nil, fmt.Errorf("创建初始请求失败: %w", err)
	}
	
	p.setRequestHeaders(req)
	
	// 不自动跟随重定向
	client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
		return http.ErrUseLastResponse
	}
	
	resp, err := client.Do(req)
	if err != nil {
		// 如果主域名失败,尝试切换到备用域名
		if p.currentBaseURL == PrimaryBaseURL {
			if p.debugMode {
				log.Printf("[Panwiki] 主域名请求失败,尝试备用域名: %v", err)
			}
			p.switchToBackupDomain()
			

View on GitHub (pinned to beaa561337)