xpzouying/xiaohongshu-mcp · error
当前 tab 为 %q,与请求的 %q 不符
Error message
当前 tab 为 %q,与请求的 %q 不符
What it means
extractUserProfileData 的一致性守卫:页面 __INITIAL_STATE__ 中 activeTab 的 query 表明当前渲染的 tab 与请求的 tab(默认 note)不一致,说明 tab 切换没有成功,直接返回会错把别的 tab 的笔记当结果。
Source
Thrown at xiaohongshu/user_profile.go:123
return nil, fmt.Errorf("failed to unmarshal userPageData: %w", err)
}
var notesData struct {
Notes [][]Feed `json:"notes"`
Index int `json:"index"`
Query string `json:"query"`
}
if err := json.Unmarshal([]byte(notesResult), ¬esData); err != nil {
return nil, fmt.Errorf("failed to unmarshal notes: %w", err)
}
// tab 不符时报错,避免把别的 tab 的内容当成结果返回
want := tab
if want == "" {
want = TabNotes
}
if notesData.Query != "" && ProfileTab(notesData.Query) != want {
return nil, fmt.Errorf("当前 tab 为 %q,与请求的 %q 不符", notesData.Query, want)
}
// 组装响应
response := &UserProfileResponse{
UserBasicInfo: userPageData.BasicInfo,
Interactions: userPageData.Interactions,
}
// 每个 tab 的内容存在各自的下标里,只取当前 tab 的,避免混入其他 tab
if notesData.Index >= 0 && notesData.Index < len(notesData.Notes) {
response.Feeds = append(response.Feeds, notesData.Notes[notesData.Index]...)
}
return response, nil
}
func makeUserProfileURL(userID, xsecToken string, tab ProfileTab) string {
url := fmt.Sprintf("https://www.xiaohongshu.com/user/profile/%s?xsec_token=%s&xsec_source=pc_note", userID, xsecToken)View on GitHub (pinned to 332d196854)
Solutions
- 不要并发复用同一个 page 请求不同 tab,串行化或为每次请求新建 page/tab
- 每次请求前显式切换/复位到目标 tab
- 升级库版本看是否已加入 tab 复位逻辑
- 捕获此错误后重建页面再重试一次
Example fix
// before res1, _ := client.UserProfile(ctx, userID, "fav") res2, err := client.UserProfile(ctx, userID, "note") // tab 残留为 fav // after mu.Lock() res1, _ := client.UserProfile(ctx, userID, "fav") mu.Unlock() mu.Lock() res2, err := client.UserProfile(ctx, userID, "note") // 串行避免 tab 竞态 mu.Unlock()
Defensive patterns
Strategy: try-catch
Validate before calling
// 请求前确认 page 未被其他 goroutine 占用、处于目标 tab
if pageBusy.Load() {
return errors.New("页面被其他请求占用,请串行化 tab 请求")
} Try / catch
res, err := client.UserProfile(ctx, userID, tab)
if err != nil && strings.Contains(err.Error(), "与请求的") && strings.Contains(err.Error(), "不符") {
// tab 残留:重建 page 后重试一次
page = newPage()
res, err = client.UserProfile(ctx, userID, tab)
} Prevention
- 不要并发复用同一个 rod.Page 请求不同 tab
- 连续请求不同 tab 之间做串行化/加锁
- 捕获 tab 不符错误后重建页面再重试
- 升级库版本确认每次请求是否已做 tab 复位
When it happens
Trigger: 调用 UserProfile / GetMyProfile 请求某个 tab,但页面当前停留的 tab 不同——例如前一次调用切换到了收藏 tab 后页面未复位,再次请求 note tab 时 activeTab.query 仍是 "fav";或并发调用共用同一个 page 导致 tab 竞态。
Common situations: 复用同一个 rod.Page 连续请求不同 tab,页面状态残留;并发请求不同 tab 互相覆盖页面状态;SPA 内部点击失败导致实际 tab 未切换。
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/066e0c3bc0f4f5e0.
Report an issue: GitHub.