{"record":{"id":"1ec6882568b4ec65","repo":"fish2018/pansou","slug":"w-1ec688","errorCode":null,"errorMessage":"解析验证数据失败: %w","messagePattern":"解析验证数据失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/gying/gying.go","lineNumber":1665,"sourceCode":"\t\tbaseTransport.Proxy = http.ProxyURL(proxyURL)\n\t}\n\n\tif DebugLog {\n\t\tfmt.Printf(\"[Gying] 已应用代理到scraper: %s\\n\", config.AppConfig.ProxyURL)\n\t}\n\n\treturn nil\n}\n\nfunc (p *GyingPlugin) solveBotChallenge(scraper *cloudscraper.Scraper, requestURL string, body []byte) error {\n\tmatches := challengeJSONPattern.FindSubmatch(body)\n\tif len(matches) < 2 {\n\t\treturn p.solveRemotePowChallenge(scraper, requestURL)\n\t}\n\n\tvar challenge ChallengePageData\n\tif err := json.Unmarshal(matches[1], &challenge); err != nil {\n\t\treturn fmt.Errorf(\"解析验证数据失败: %w\", err)\n\t}\n\n\tif challenge.ID != \"\" && challenge.N != \"\" && challenge.X != \"\" && challenge.T > 0 {\n\t\treturn p.solvePowChallenge(scraper, requestURL, &challenge)\n\t}\n\n\treturn p.solveLegacyHashChallenge(scraper, requestURL, &challenge)\n}\n\nfunc (p *GyingPlugin) solveRemotePowChallenge(scraper *cloudscraper.Scraper, requestURL string) error {\n\tpowURL, err := p.buildPowURL(requestURL)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif DebugLog {\n\t\tfmt.Printf(\"[Gying] Remote PoW Challenge命中: url=%s powURL=%s\\n\", requestURL, powURL)\n\t}","sourceCodeStart":1647,"sourceCodeEnd":1683,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/gying/gying.go#L1647-L1683","documentation":"When the plugin receives an anti-bot challenge page, it extracts an embedded JSON payload (matches[1]) with the challenge parameters and unmarshals it into ChallengePageData. If json.Unmarshal fails — the extracted blob is not valid JSON or doesn't match the expected shape (e.g. it's HTML-wrapped or the site changed its page format) — the error is wrapped as '解析验证数据失败: %w'.","triggerScenarios":"The regex matched a challenge script on the page but the captured group contains malformed or non-canonical JSON (HTML entities, trailing garbage, new site page layout), so json.Unmarshal into ChallengePageData errors before the POW solver can run.","commonSituations":"Upstream site updated its challenge page format so the regex grabs the wrong region; response decompressed/escaped differently than expected; site returns a different captcha variant whose payload isn't the expected JSON object.","solutions":["Log the wrapped %w error plus matches[1] (truncated) to see the actual payload, then update the extraction regex/decoding (e.g. html.UnescapeString) for the new page format.","Sanitize the blob before unmarshaling: strip surrounding quotes/backslashes (if JSON-in-string, json.Unmarshal into a string first) and trim non-JSON trailing characters.","Check if the page is actually a different challenge type and route it to solveRemotePowChallenge or another solver instead of parsing it as POW data.","Update ChallengePageData field tags if the site renamed fields, so unmarshal succeeds."],"exampleFix":"// before\nif err := json.Unmarshal(matches[1], &challenge); err != nil {\n    return fmt.Errorf(\"解析验证数据失败: %w\", err)\n}\n// after\nblob := []byte(html.UnescapeString(string(matches[1])))\nif err := json.Unmarshal(blob, &challenge); err != nil {\n    return p.solveRemotePowChallenge(scraper, requestURL) // fall back for unexpected formats\n}","handlingStrategy":"fallback","validationCode":"func looksLikeChallengeJSON(s string) bool {\n    var c struct { ID string `json:\"id\"`; N string `json:\"n\"`; X string `json:\"x\"`; T int64 `json:\"t\"` }\n    return json.Unmarshal([]byte(s), &c) == nil && c.ID != \"\" && c.N != \"\"\n}\n// if false, skip POW parsing and use the remote-challenge path","typeGuard":null,"tryCatchPattern":"challenge, err := parseChallengeFromBody(body)\nif err != nil {\n    if strings.Contains(err.Error(), \"解析验证数据失败\") {\n        return p.solveRemotePowChallenge(scraper, requestURL) // graceful fallback\n    }\n    return err\n}","preventionTips":["HTML-unescape and trim the extracted payload before json.Unmarshal.","Log a truncated sample of the raw page whenever parsing fails to catch upstream format changes early.","Add a regression test with a saved copy of a real challenge page to detect upstream format changes.","Prefer extracting JSON via a quoted-string decode (unmarshal into string first) instead of raw regex capture when the payload is JSON-in-HTML."],"tags":["json","anti-bot","challenge","html-scraping"],"backgroundTag":"json-unmarshal-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"}