jackwener/OpenCLI · error · AuthRequiredError

Note comments require login

Error message

Note comments require login

What it means

The extractor sets data.loginWall when the note detail page requires authentication to view comments. The command converts this into AuthRequiredError for www.xiaohongshu.com with the message 'Note comments require login', telling callers to authenticate the browser session.

Source

Thrown at clis/xiaohongshu/comments.js:315

    columns: ['rank', 'author', 'userId', 'profileUrl', 'text', 'likes', 'time', 'is_reply', 'reply_to', 'images'],
    func: async (page, kwargs) => {
        const limit = parseCommentLimit(kwargs.limit);
        const withReplies = Boolean(kwargs['with-replies']);
        const raw = String(kwargs['note-id']);
        const noteId = parseNoteId(raw);
        await page.goto(buildNoteUrl(raw, { commandName: 'xiaohongshu comments' }));
        await page.wait({ time: 2 + Math.random() * 3 });
        const data = await page.evaluate(buildCommentsExtractJs(withReplies, limit));
        if (!data || typeof data !== 'object') {
            throw new EmptyResultError('xiaohongshu/comments', 'Unexpected evaluate response');
        }
        if (data.securityBlock) {
            throw new CliError('SECURITY_BLOCK', 'Xiaohongshu security block: the note detail page was blocked by risk control.', /^https?:\/\//.test(raw)
                ? 'The page may be temporarily restricted. Try again later or from a different session.'
                : 'Try using a full URL from search results (with xsec_token) instead of a bare note ID.');
        }
        if (data.loginWall) {
            throw new AuthRequiredError('www.xiaohongshu.com', 'Note comments require login');
        }
        // noteId currently unused after parsing — kept for symmetry with the note command
        void noteId;
        const all = normalizeCommentRows(data.results, 'xiaohongshu/comments');
        // authorHrefRaw is a raw transport field from the extractor; it is consumed
        // here into userId / profileUrl and intentionally not part of the row shape.
        const enrich = (c, i) => ({
            rank: i + 1,
            author: c.author,
            userId: c.authorHrefRaw ? parseXhsProfileHref(c.authorHrefRaw) : '',
            profileUrl: c.authorHrefRaw ? buildXhsProfileUrl(c.authorHrefRaw) : '',
            text: c.text,
            likes: c.likes,
            time: c.time,
            is_reply: c.is_reply,
            reply_to: c.reply_to,
            images: c.images ?? [],
        });

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log in once so the session cookies persist, then rerun the command
  2. Refresh/re-authenticate — cookies may have expired
  3. Check whether the specific note requires membership or is region-restricted
  4. Update the library if Xiaohongshu changed login-wall markup and the flag misfires

Example fix

// before
const cli = new XiaohongshuCli(); // anonymous session
await cli.comments(noteUrl);
// after
const cli = new XiaohongshuCli({ userDataDir: './xhs-profile' });
await cli.login(); // persist cookies once
await cli.comments(noteUrl);
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const comments = await cli.comments(noteUrl);
} catch (err) {
  if (err instanceof AuthRequiredError || /require login/i.test(err.message)) {
    await cli.login(); // authenticate session then retry
    return cli.comments(noteUrl);
  }
  throw err;
}

Prevention

When it happens

Trigger: page.evaluate returns { loginWall: true } — the page rendered a login prompt/redirect instead of the comment list, typically for notes whose comments are members-only or when the session is anonymous.

Common situations: Running without a logged-in session (no cookies persisted); Xiaohongshu now requires login for comment viewing where it previously did not (policy change); expired session cookies; accessing comments of restricted/PGC notes.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/82c5ec5d07853386. Report an issue: GitHub.