fish2018/pansou · error
登录成功但未获取到有效 Cookie
Error message
登录成功但未获取到有效 Cookie
What it means
The login response reported Success=true, but the cookie jar contained no cookies for the base URL, so cookiesToString produced an empty string. Without a cookie the session cannot be reused, so the plugin refuses to return a useless empty credential.
Solutions
- Parse the cookie base URL from the actual login response URL instead of hardcoding DefaultBaseURL
- Check the jar error from cookiejar.New instead of discarding it
- Inspect Set-Cookie headers of the login response directly as a fallback
- Update DefaultBaseURL if the site changed domains
Example fix
// before
jar, _ := cookiejar.New(nil)
...
baseURL, _ := url.Parse(DefaultBaseURL)
// after
jar, err := cookiejar.New(nil)
if err != nil { return "", nil, err }
...
baseURL, _ := url.Parse(resp.Request.URL.String()) Defensive patterns
Strategy: fallback
Validate before calling
if len(resp.Cookies()) == 0 {
return errors.New("login response carried no Set-Cookie headers")
} Try / catch
cookieString, loginResp, err := p.doLogin(u, p, true)
if err != nil {
if strings.Contains(err.Error(), "未获取到有效 Cookie") {
return fmt.Errorf("session establishment failed; check cookie domain config: %w", err)
}
return err
} Prevention
- Derive the cookie domain from the actual response URL, not a hardcoded base URL
- Handle the error from cookiejar.New instead of discarding it
- Log Set-Cookie headers during login debugging
When it happens
Trigger: Upstream returns success JSON but sets cookies on a different domain/path than DefaultBaseURL, sets no cookies at all, or cookiejar.New failed silently (error ignored) leaving no jar.
Common situations: Site changed cookie domain (e.g. moved to a subdomain); SameSite/secure attribute changes; upstream success response no longer establishes a session cookie.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/ad1ccfe608c7d0d4.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/panlian/panlian.go:1135
cancel()
if err != nil {
return "", nil, err
}
if resp.StatusCode != http.StatusOK {
return "", nil, fmt.Errorf("登录请求失败: HTTP %d", resp.StatusCode)
}
var loginResp LoginResponse
if err := json.Unmarshal(respBody, &loginResp); err != nil {
return "", nil, fmt.Errorf("解析登录响应失败: %w", err)
}
if !loginResp.Success {
return "", nil, errors.New(strings.TrimSpace(loginResp.Message))
}
cookieString := cookiesToString(jar.Cookies(baseURL))
if cookieString == "" {
return "", nil, fmt.Errorf("登录成功但未获取到有效 Cookie")
}
return cookieString, &loginResp, nil
}
func (p *PanlianPlugin) reloginUser(user *User) error {
password, err := p.decryptPassword(user.EncryptedPassword)
if err != nil {
return err
}
cookie, _, err := p.doLogin(user.Username, password, true)
if err != nil {
user.Status = "expired"
user.Cookie = ""
_ = p.saveUser(user)
return err
}
View on GitHub (pinned to beaa561337)