{"record":{"id":"377bbcabb648d8f1","repo":"fish2018/pansou","slug":"s-http-d-377bbc","errorCode":null,"errorMessage":"[%s] 搜索请求返回 HTTP %d","messagePattern":"\\[(.+?)\\] 搜索请求返回 HTTP (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/dygang/dygang.go","lineNumber":185,"sourceCode":"\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 编码搜索关键词失败: %w\", p.Name(), err)\n\t}\n\tform := \"tempid=1&tbname=article&keyboard=\" + url.QueryEscape(string(encoded)) + \"&show=title%2Csmalltext&Submit=\"\n\tctx, cancel := context.WithTimeout(context.Background(), requestTimeout)\n\tdefer cancel()\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, baseURL+searchPath, strings.NewReader(form))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 创建搜索请求失败: %w\", p.Name(), err)\n\t}\n\tsetHeaders(req, baseURL+\"/\")\n\treq.Header.Set(\"Content-Type\", \"application/x-www-form-urlencoded\")\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 搜索请求失败: %w\", p.Name(), err)\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"[%s] 搜索请求返回 HTTP %d\", p.Name(), resp.StatusCode)\n\t}\n\tbody, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 读取搜索结果失败: %w\", p.Name(), err)\n\t}\n\tdecoded, err := decodeGB18030(body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 解码搜索结果失败: %w\", p.Name(), err)\n\t}\n\tdoc, err := goquery.NewDocumentFromReader(strings.NewReader(decoded))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 解析搜索结果失败: %w\", p.Name(), err)\n\t}\n\treturn doc, nil\n}\n\nfunc (p *Plugin) fetchDetail(client *http.Client, detailURL string) ([]magnetItem, string, string) {\n\tctx, cancel := context.WithTimeout(context.Background(), requestTimeout)","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/dygang/dygang.go#L167-L203","documentation":"The HTTP request succeeded but the server responded with a status code other than 200 OK, so the plugin refuses to parse the body and returns this error. The site likely returned a redirect to a captcha/login page, a 403 anti-bot response, a 404, or a 5xx server error. Note the message does not wrap an underlying error — the status code itself is the information.","triggerScenarios":"After client.Do, resp.StatusCode != http.StatusOK for the POST to baseURL+searchPath — e.g. 403 from WAF/anti-bot, 404 after a site URL structure change, 302 to a verification page, 500/502/503 from the upstream server.","commonSituations":"The target site changed its URL or enabled anti-scraping (Cloudflare challenge), an outdated baseURL in config, rate-limiting after frequent searches, or transient upstream outages.","solutions":["Log or inspect resp.StatusCode (and the body) to identify what the server actually returned.","Update the plugin's baseURL/searchPath if the site moved (404 case).","Check cookies/headers: add realistic User-Agent and reuse cookies if the site requires a session (403/captcha case).","Back off and retry later for 5xx responses."],"exampleFix":"// before\nif resp.StatusCode != http.StatusOK {\n\treturn nil, fmt.Errorf(\"[%s] 搜索请求返回 HTTP %d\", p.Name(), resp.StatusCode)\n}\n// after\nif resp.StatusCode != http.StatusOK {\n\tsnippet, _ := io.ReadAll(io.LimitReader(resp.Body, 512))\n\treturn nil, fmt.Errorf(\"[%s] 搜索请求返回 HTTP %d, body: %s\", p.Name(), resp.StatusCode, snippet)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if resp.StatusCode != http.StatusOK {\n\treturn fmt.Errorf(\"HTTP %d: inspect headers/body for captcha, redirect, or outage\", resp.StatusCode)\n}","preventionTips":["Send realistic User-Agent and Accept headers to reduce anti-bot 403s","Reuse cookies/session from an initial page visit","Back off on 5xx instead of hammering retries","Alert on status-code changes — they usually mean the site changed"],"tags":["http","status-code","anti-bot","scraping"],"backgroundTag":"http-non-200-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"}