{"record":{"id":"d80a617351d36c93","repo":"fish2018/pansou","slug":"cookie-s","errorCode":null,"errorMessage":"缺少必需的Cookie字段: %s","messagePattern":"缺少必需的Cookie字段: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/weibo/weibo.go","lineNumber":1961,"sourceCode":"\t}\n\tfor _, cookie := range jar.Cookies(weiboCNURL) {\n\t\tallCookies[cookie.Name] = cookie.Value\n\t}\n\t\n\tfmt.Printf(\"[Weibo DEBUG] 收集到的Cookie字段: %v\\n\", func() []string {\n\t\tkeys := make([]string, 0, len(allCookies))\n\t\tfor k := range allCookies {\n\t\t\tkeys = append(keys, k)\n\t\t}\n\t\treturn keys\n\t}())\n\t\n\t// 检查必需的Cookie字段\n\trequiredFields := []string{\"SUB\", \"SUBP\"}\n\tfor _, field := range requiredFields {\n\t\tif _, exists := allCookies[field]; !exists {\n\t\t\tfmt.Printf(\"[Weibo DEBUG] 缺少必需的Cookie字段: %s\\n\", field)\n\t\t\treturn \"\", fmt.Errorf(\"缺少必需的Cookie字段: %s\", field)\n\t\t} else {\n\t\t\tfmt.Printf(\"[Weibo DEBUG] ✓ 找到必需字段: %s\\n\", field)\n\t\t}\n\t}\n\t\n\t// 构建Cookie字符串\n\tcookieParts := make([]string, 0, len(allCookies))\n\tfor k, v := range allCookies {\n\t\tcookieParts = append(cookieParts, fmt.Sprintf(\"%s=%s\", k, v))\n\t}\n\t\n\tcookieStr := strings.Join(cookieParts, \"; \")\n\tfmt.Printf(\"[Weibo DEBUG] Cookie初始化完成, 总长度: %d, 字段数: %d\\n\", len(cookieStr), len(allCookies))\n\t\n\treturn cookieStr, nil\n}\n\nfunc (p *WeiboPlugin) generateHash(input string) string {","sourceCodeStart":1943,"sourceCodeEnd":1979,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/weibo/weibo.go#L1943-L1979","documentation":"Raised by initCookieFromAlt when the cookies collected from the alt redirect URL do not include one of the required session fields SUB and SUBP. These two cookies are Weibo's long-lived session identifiers; without them the login is not usable, so the function returns an empty cookie string and this error, which checkQRLoginStatus then wraps as \"初始化Cookie失败\". The %s names exactly which field is missing.","triggerScenarios":"After following the alt URL returned by a successful QR scan, the collected cookie jar lacks SUB or SUBP — the redirect chain didn't set it, or the plugin's cookie collection missed the domain/path it was set on.","commonSituations":"Weibo changed which domains set SUB/SUBP (cookie collection filtered to the wrong host); the scan was confirmed but Weibo issued a degraded session (risk control); alt URL already consumed/expired; HTTP (non-HTTPS) or redirected requests where Set-Cookie was dropped by the client or a proxy.","solutions":["Read the missing field name from the message and log all cookies received from the alt redirect to see what actually came back.","Ensure the HTTP client follows redirects and stores cookies for all Weibo domains (.weibo.com, .sina.com.cn) — disable any cookie-domain filtering.","Retry with a fresh QR code; expired/consumed alt URLs yield incomplete sessions.","Check Weibo risk-control signals (same IP repeatedly logging in, missing User-Agent) that can suppress SUB issuance.","If Weibo changed the login contract, update requiredFields / cookie collection logic in initCookieFromAlt."],"exampleFix":"// before\nrequiredFields := []string{\"SUB\", \"SUBP\"}\nfor _, field := range requiredFields {\n    if _, exists := allCookies[field]; !exists {\n        return \"\", fmt.Errorf(\"缺少必需的Cookie字段: %s\", field)\n    }\n}\n// after: follow redirects explicitly and log received cookies for diagnosis\nrequiredFields := []string{\"SUB\", \"SUBP\"}\nfor _, field := range requiredFields {\n    if _, exists := allCookies[field]; !exists {\n        names := make([]string, 0, len(allCookies))\n        for k := range allCookies {\n            names = append(names, k)\n        }\n        return \"\", fmt.Errorf(\"缺少必需的Cookie字段: %s (收到: %v)\", field, names)\n    }\n}","handlingStrategy":"validation","validationCode":"// Go: verify SUB/SUBP present in the cookie jar before calling the login flow's final step\nfunc hasSessionCookies(jar http.CookieJar, u *url.URL) bool {\n    have := map[string]bool{}\n    for _, c := range jar.Cookies(u) {\n        have[c.Name] = true\n    }\n    return have[\"SUB\"] && have[\"SUBP\"]\n}","typeGuard":"func cookiesComplete(allCookies map[string]string) bool {\n    _, hasSUB := allCookies[\"SUB\"]\n    _, hasSUBP := allCookies[\"SUBP\"]\n    return hasSUB && hasSUBP\n}","tryCatchPattern":"cookie, err := plugin.Login(...) // surfaces 缺少必需的Cookie字段 via wrapper\nif err != nil {\n    if strings.Contains(err.Error(), \"缺少必需的Cookie字段\") {\n        // session degraded or cookie collection missed a domain; fresh QR + unrestricted jar\n        return retryQRLogin(plugin, 1)\n    }\n    return err\n}","preventionTips":["Configure the cookie jar to accept Set-Cookie from all Weibo/Sina domains the redirect chain touches.","Send consistent User-Agent and use HTTPS so Set-Cookie headers are not stripped by proxies.","Log all received cookie names when SUB/SUBP are missing to spot domain or format changes.","Retry with a new QR code; a consumed or risk-flagged alt URL yields incomplete sessions."],"tags":["weibo","cookie","authentication","session"],"backgroundTag":"missing-credentials","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"}