fish2018/pansou · error
创建cloudscraper失败
Error message
创建cloudscraper失败: %w
What it means
Wraps the error from cloudscraper.New... when creating the browser-like scraper instance in createScraperWithCookies. Construction failed before any request was made. Note: if applyProxyToScraper fails afterwards, a sibling error '应用代理失败' is returned instead.
Solutions
- Unwrap the cause with errors.Unwrap to see the constructor's message.
- Verify the cloudscraper module version supports the options passed (browser emulation args, refreshOn403, interval, maxRetries).
- Run go mod tidy / go build to fix dependency corruption.
- Confirm the cookie string parses if cookies are applied immediately after creation.
Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := cloudscraper.New(); err != nil { return fmt.Errorf("cloudscraper unusable in this build: %w", err) } // at startup Try / catch
scraper, err := p.createScraperWithCookies(cookies); if err != nil { return fmt.Errorf("scraper init: %w", errors.Unwrap(err)) } Prevention
- Smoke-test scraper creation at startup, not on first request
- Pin a compatible cloudscraper version
- Keep go.sum/tidy clean to avoid corrupted deps
- Validate cookie strings before passing them in
When it happens
Trigger: createScraperWithCookies builds a cloudscraper with custom browser emulation options and refreshOn403=false; the constructor returns a non-nil err (e.g. invalid option combination or internal init failure).
Common situations: Incompatible cloudscraper version lacking expected options, invalid cookie string downstream, or corrupted dependency install.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/778aca0f9c85bc43.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/gying/gying.go:1973
}
return nil, 0, nil, fmt.Errorf("请求重试次数已耗尽")
}
// createScraperWithCookies 创建一个带有指定cookies的cloudscraper实例
// 使用反射访问内部的http.Client并设置cookies到cookiejar
// 关键:禁用session refresh以防止cookies被清空
func (p *GyingPlugin) createScraperWithCookies(cookieStr string) (*cloudscraper.Scraper, error) {
// 创建cloudscraper实例,配置以保护cookies不被刷新
scraper, err := cloudscraper.New(
cloudscraper.WithSessionConfig(
false, // refreshOn403 = false,禁用403时自动刷新
365*24*time.Hour, // interval = 1年,基本不刷新
0, // maxRetries = 0
),
)
if err != nil {
return nil, fmt.Errorf("创建cloudscraper失败: %w", err)
}
if err := p.applyProxyToScraper(scraper); err != nil {
return nil, fmt.Errorf("应用代理失败: %w", err)
}
// 如果有保存的cookies,使用反射设置到scraper的内部http.Client
if cookieStr != "" {
cookies := parseCookieString(cookieStr)
if DebugLog {
fmt.Printf("[Gying] 正在恢复 %d 个cookie到scraper实例\n", len(cookies))
}
// 使用反射访问scraper的unexported client字段
scraperValue := reflect.ValueOf(scraper).Elem()
clientField := scraperValue.FieldByName("client")
if clientField.IsValid() && !clientField.IsNil() {View on GitHub (pinned to beaa561337)