{"record":{"id":"1da029e163ce7e08","repo":"fish2018/pansou","slug":"s-token-w-1da029","errorCode":null,"errorMessage":"[%s] token请求失败: %w","messagePattern":"\\[(.+?)\\] token请求失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/xys/xys.go","lineNumber":163,"sourceCode":"\tdefer cancel()\n\n\treq, err := http.NewRequestWithContext(ctx, \"GET\", tokenURL, nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"[%s] 创建token请求失败: %w\", p.Name(), err)\n\t}\n\n\t// 设置完整的请求头\n\treq.Header.Set(\"User-Agent\", UserAgent)\n\treq.Header.Set(\"Accept\", \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\")\n\treq.Header.Set(\"Accept-Language\", \"zh-CN,zh;q=0.9,en;q=0.8\")\n\treq.Header.Set(\"Connection\", \"keep-alive\")\n\treq.Header.Set(\"Upgrade-Insecure-Requests\", \"1\")\n\treq.Header.Set(\"Cache-Control\", \"max-age=0\")\n\treq.Header.Set(\"Referer\", BaseURL+\"/\")\n\n\tresp, err := p.doRequestWithRetry(req, client)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"[%s] token请求失败: %w\", p.Name(), err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != 200 {\n\t\treturn \"\", fmt.Errorf(\"[%s] token请求HTTP状态错误: %d\", p.Name(), resp.StatusCode)\n\t}\n\n\t// 解析HTML提取token\n\tdoc, err := goquery.NewDocumentFromReader(resp.Body)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"[%s] 解析token页面HTML失败: %w\", p.Name(), err)\n\t}\n\n\t// 查找script标签中的DToken定义\n\tvar token string\n\tdoc.Find(\"script\").Each(func(i int, s *goquery.Selection) {\n\t\tscriptContent := s.Text()\n\t\tif strings.Contains(scriptContent, \"DToken\") {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/xys/xys.go#L145-L181","documentation":"getToken wraps the error returned by doRequestWithRetry, which performed the token page GET and exhausted its retry loop (connection errors, timeouts, TLS failures). The token could not be fetched from the remote site, so searchImpl cannot proceed. The wrapped cause is the last network error observed across all retries.","triggerScenarios":"p.doRequestWithRetry(req, client) returns an error — all retry attempts to GET the token page failed (dial errors, context deadline of the 30s timeout, TLS handshake failure, connection reset).","commonSituations":"Target site blocked/down or geo-restricted; corporate proxy/firewall intercepting; DNS failure; client timeout too short for a slow upstream; missing proxy env config.","solutions":["Unwrap and log the inner error (%w chain) to see the concrete cause (timeout vs refused vs TLS)","Verify network reachability: curl the token URL from the same host, check DNS and proxy settings (HTTP_PROXY/HTTPS_PROXY)","Increase the 30s context timeout or the retry count/backoff in doRequestWithRetry if upstream is slow","Check whether the site requires cookies/anti-bot handling that redirects in a way the client rejects"],"exampleFix":"null","handlingStrategy":"retry","validationCode":"// pre-check reachability\nconn, err := net.DialTimeout(\"tcp\", host+\":443\", 5*time.Second)\nif err != nil { return fmt.Errorf(\"unreachable: %w\", err) }\nconn.Close()","typeGuard":null,"tryCatchPattern":"if err != nil {\n    var ne net.Error\n    if errors.As(err, &ne) && ne.Timeout() {\n        return retryWithBackoff(ctx)\n    }\n    return nil, fmt.Errorf(\"token fetch failed permanently: %w\", err)\n}","preventionTips":["Configure proxy env vars correctly in restricted networks","Set realistic timeouts; avoid very short deadlines on slow upstreams","Monitor upstream availability and cache tokens to reduce request volume"],"tags":["network","http","retry-exhausted","timeout"],"backgroundTag":"network-request-failed","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}