fish2018/pansou · error
无法解析code字段,类型: %T, 值
Error message
无法解析code字段,类型: %T, 值: %v
What it means
The parsed login JSON stores its 'code' field as interface{}, so gying converts it via fmt.Sprintf("%v") + strconv.Atoi. If the value is neither a number nor a numeric string (e.g. bool, nested object, or missing→nil), Atoi fails and the plugin returns '无法解析code字段,类型: %T, 值: %v', reporting the Go type and value it couldn't parse.
Solutions
- Log the full raw response body and check the actual shape of the 'code' field against the error's %T/%v output.
- Compare with the site's current API docs or a manual login (browser devtools) to see the new response schema.
- Update the plugin to handle the new schema (e.g. accept string statuses or a renamed field).
- If the field is missing entirely, the endpoint likely returned an error payload — fix the request (credentials, cookies) and retry.
Example fix
// before: only numeric/string-numeric accepted
parsed, err := strconv.Atoi(codeStr)
// after: also treat a bool-style or mapped status defensively
if s, ok := codeInterface.(string); ok {
parsed, err = strconv.Atoi(strings.TrimSpace(s))
} Defensive patterns
Strategy: type-guard
Type guard
func codeFieldIsNumeric(loginResp map[string]interface{}) bool {
switch v := loginResp["code"].(type) {
case float64, int, string:
return true
default:
_ = v
return false
}
} Prevention
- Log the raw login response whenever the schema might have changed.
- Validate response shape before interpreting business fields.
- Update plugin handling if the site converts code to a string status.
- Treat missing 'code' as an error-payload signal, not a parse bug.
When it happens
Trigger: Login response JSON contains a 'code' field whose value is not numeric — a string like "ok", an object, a boolean, or the field is absent so codeInterface is nil.
Common situations: Site changed its login API response schema (code moved/renamed, became a string status); response is actually an error payload with a different shape; partial/HTML-ish body that unmarshaled as something unexpected.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/153aec1b8fbdffee.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/gying/gying.go:2200
var codeValue int
codeInterface := loginResp["code"]
switch v := codeInterface.(type) {
case int:
codeValue = v
case float64:
codeValue = int(v)
case int64:
codeValue = int(v)
default:
// 尝试转换为字符串再解析
codeStr := fmt.Sprintf("%v", codeInterface)
parsed, err := strconv.Atoi(codeStr)
if err != nil {
if DebugLog {
fmt.Printf("[Gying] 无法解析code字段: %T, 值: %v, 错误: %v\n", codeInterface, codeInterface, err)
}
return nil, "", fmt.Errorf("无法解析code字段,类型: %T, 值: %v", codeInterface, codeInterface)
}
codeValue = parsed
}
if DebugLog {
fmt.Printf("[Gying] 解析后的code值: %d\n", codeValue)
}
if codeValue != 200 {
if DebugLog {
fmt.Printf("[Gying] 登录失败: code=%d (期望200)\n", codeValue)
}
return nil, "", fmt.Errorf("登录失败: code=%d, 响应=%s", codeValue, string(body))
}
// ========== 步骤3: GET详情页 (触发防爬cookies如vrg_sc、vrg_go等) ==========
if DebugLog {
fmt.Printf("[Gying] 步骤3: GET详情页收集完整Cookie\n")View on GitHub (pinned to beaa561337)