{"record":{"id":"7e27e1e02ce5989c","repo":"fish2018/pansou","slug":"gzip-w","errorCode":null,"errorMessage":"创建gzip读取器失败: %w","messagePattern":"创建gzip读取器失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/qupanshe/qupanshe.go","lineNumber":182,"sourceCode":"\t\tif u, _ := url.Parse(BaseURL); u != nil {\n\t\t\tcookies := client.Jar.Cookies(u)\n\t\t\tfmt.Printf(\"[qupanshe] 从首页获取到 %d 个cookies:\\n\", len(cookies))\n\t\t\tfor i, cookie := range cookies {\n\t\t\t\tfmt.Printf(\"  Cookie[%d]: %s=%s\\n\", i, cookie.Name, cookie.Value)\n\t\t\t}\n\t\t}\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"首页请求返回状态码: %d\", resp.StatusCode)\n\t}\n\n\t// 处理可能的gzip压缩\n\tvar reader io.Reader = resp.Body\n\tif resp.Header.Get(\"Content-Encoding\") == \"gzip\" {\n\t\tgzipReader, err := gzip.NewReader(resp.Body)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"创建gzip读取器失败: %w\", err)\n\t\t}\n\t\tdefer gzipReader.Close()\n\t\treader = gzipReader\n\t}\n\n\t// 解析HTML\n\tdoc, err := goquery.NewDocumentFromReader(reader)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"解析HTML失败: %w\", err)\n\t}\n\n\t// 查找formhash\n\tformhash := \"\"\n\tinputCount := doc.Find(\"input[name='formhash']\").Length()\n\tif DebugLog {\n\t\tfmt.Printf(\"[qupanshe] 找到input[name='formhash']元素数量: %d\\n\", inputCount)\n\t}\n","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/qupanshe/qupanshe.go#L164-L200","documentation":"getFormhash wraps a failure from gzip.NewReader when the homepage response declares Content-Encoding: gzip. The library attempts manual gzip decoding; if the body is not valid gzip data, this error is returned.","triggerScenarios":"Response header Content-Encoding == gzip but resp.Body is not a valid gzip stream — e.g., double decompression by transport, corrupted body, or a mislabeled Content-Encoding header.","commonSituations":"Custom Transport that already decompresses while the header still says gzip, middleboxes/proxies mangling the response, or CDN sending inconsistent headers.","solutions":["If using a custom Transport, ensure DisableCompression is false so net/http handles gzip transparently (then the manual path won't trigger)","Inspect raw response bytes to confirm whether they're actually gzip","Retry the request; the body may be corrupted transiently","Handle both gzip and deflate/br encodings defensively"],"exampleFix":"// before\ntr := &http.Transport{DisableCompression: true}\n// after\ntr := &http.Transport{} // let net/http auto-decompress gzip","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"创建gzip读取器失败\") {\n    // compression mismatch; retry — transport may decompress next time\n    return retryOnce(err)\n}","preventionTips":["Do not set Transport.DisableCompression to true while also manually handling gzip","Avoid custom Transports that decompress but keep the gzip header","Log raw body prefix when this occurs to diagnose encodings"],"tags":["go","gzip","http","encoding"],"backgroundTag":"invalid-json-response","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"}