jackwener/OpenCLI · error · AuthRequiredError

www.xiaohongshu.com

Error message

www.xiaohongshu.com

What it means

AuthRequiredError('www.xiaohongshu.com') is thrown when the final page URL is on xiaohongshu.com but its path looks like a login page (/login...). The site redirected the browser to login because the session cookies are missing, expired, or invalid, so the unfollow action cannot proceed unauthenticated.

Source

Thrown at clis/xiaohongshu/unfollow.js:220

        }
        try {
            const userId = assertUserId(kwargs['user-id']);
            const url = `https://www.xiaohongshu.com/user/profile/${userId}`;
            await page.goto(url);
            await page.wait({ time: PROFILE_SETTLE_MS / 1000 });

            const hrefRaw = unwrapEvaluateResult(await page.evaluate('() => location.href'));
            if (typeof hrefRaw !== 'string') {
                throw new CommandExecutionError('xiaohongshu/unfollow: malformed current-url payload');
            }
            const parsedHref = new URL(hrefRaw);
            if (parsedHref.protocol !== 'https:' || !isXiaohongshuHost(parsedHref.hostname)) {
                throw new CommandExecutionError(
                    `xiaohongshu/unfollow: expected Xiaohongshu profile host, got ${parsedHref.hostname}`,
                );
            }
            if (/\/login(?:[/?#]|$)/i.test(parsedHref.pathname)) {
                throw new AuthRequiredError('www.xiaohongshu.com');
            }
            const currentProfile = parsedHref.pathname.match(/^\/user\/profile\/([a-zA-Z0-9]{8,32})\/?$/);
            if (currentProfile?.[1] !== userId) {
                throw new CommandExecutionError(
                    `xiaohongshu/unfollow: expected profile ${userId}, got ${parsedHref.pathname}`,
                );
            }

            // Step 1: click 已关注 (idempotent — bails out if 关注 is visible)
            const clickResult = requireActionResult(
                await page.evaluate(buildClickUnfollowScript()),
                'click-unfollow',
            );
            if (!clickResult.ok) {
                throw new CommandExecutionError(
                    `xiaohongshu/unfollow failed: ${clickResult.reason ?? 'unknown reason'}`,
                );
            }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log into www.xiaohongshu.com in the automated Chrome browser (scan the QR code) and re-run the command
  2. Refresh/sync the cookie session used by the CLI (re-export cookies from a logged-in browser)
  3. Check the account in a normal browser: if you were logged out or restricted, recover the login first
  4. Re-run after completing any risk-control verification the site showed

Example fix

// before: run with expired cookies
$ xiaohongshu unfollow <id>   # -> AuthRequiredError('www.xiaohongshu.com')
// after: re-login in the automated Chrome, then
$ xiaohongshu unfollow <id>
Defensive patterns

Strategy: try-catch

Validate before calling

// verify cookies exist before running
const hasSession = document.cookie.includes('web_session'); // run inside the xiaohongshu browser context

Try / catch

try { await cli.unfollow({ 'user-id': id }); } catch (e) { if (e.name === 'AuthRequiredError' || String(e.message) === 'www.xiaohongshu.com') { await loginFlow(); /* re-login then retry */ } else throw e; }

Prevention

When it happens

Trigger: Cookie session expired or was invalidated (logged out elsewhere, password change); the automated Chrome profile was never logged in; cookies cleared between runs; the site forces re-login due to risk control; Strategy.COOKIE session synced stale/expired cookies.

Common situations: Long-lived automation environments where the session silently expired; switching Chrome profiles; running after xiaohongshu logged the account out for security reasons; running two sessions that invalidate each other's cookies.

Related errors


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