xpzouying/xiaohongshu-mcp · error
设置可见范围失败
Error message
设置可见范围失败
What it means
Raised in submitPublish when setVisibility fails to select the desired visibility (public/private/followers-only) on the Xiaohongshu publish form. The library wraps the underlying error so callers know the failure occurred at the visibility-selection step rather than another publish step.
Source
Thrown at xiaohongshu/publish.go:390
return err
}
humanize.Delay(ctx, humanize.AfterType)
if err := checkContentMaxLength(page); err != nil {
return err
}
slog.Info("检查正文长度:通过")
if scheduleTime != nil {
if err := setSchedulePublish(ctx, page, *scheduleTime); err != nil {
return errors.Wrap(err, "设置定时发布失败")
}
slog.Info("定时发布设置完成", "schedule_time", scheduleTime.Format("2006-01-02 15:04"))
}
if err := setVisibility(page, visibility); err != nil {
return errors.Wrap(err, "设置可见范围失败")
}
// 处理原创声明:显式请求了原创但设置失败 → 报错中止,不静默发成非原创(避免"以为原创其实不是")
if isOriginal {
if err := setOriginal(page); err != nil {
return errors.Wrap(err, "设置原创声明失败(已请求原创,中止发布)")
}
slog.Info("已声明原创")
}
if err := bindProducts(ctx, page, products); err != nil {
return errors.Wrap(err, "绑定商品失败")
}
if err := clickPublishButton(page); err != nil {
return err
}
View on GitHub (pinned to 332d196854)
Solutions
- Check the visibility value is a supported option of this library
- Retry the publish; DOM timing races often pass on retry
- Inspect the wrapped cause for the exact missing selector
- Update the library or patch setVisibility selectors to match the current Xiaohongshu page
Example fix
// before err := xhs.Publish(..., visibility="friends", ...) // unsupported/renamed option // after err := xhs.Publish(..., visibility=xhs.VisibilityPrivate, ...) // use supported constant
Defensive patterns
Strategy: validation
Validate before calling
supported := map[string]bool{"public":true,"private":true,"followers":true}
if !supported[visibility] {
return errors.Errorf("不支持的可见范围: %s", visibility)
} Try / catch
if err := xhs.Publish(...); err != nil {
if strings.Contains(err.Error(), "设置可见范围失败") {
// fall back to default visibility and retry
}
} Prevention
- Use only visibility constants documented by the library
- Retry once on transient DOM timing failures
- Inspect errors.Unwrap for the missing selector
- Update selectors after Xiaohongshu UI changes
When it happens
Trigger: Calling Publish with a visibility value whose corresponding UI control cannot be found or clicked: the visibility selector DOM changed, the option label no longer matches, or the page element is not interactable.
Common situations: Xiaohongshu updated the publish page and the visibility option labels/selectors no longer match; passing an unsupported visibility constant; page not fully loaded when the step runs.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/84e4cb3b31e2a9f0.
Report an issue: GitHub.