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
- Log into www.xiaohongshu.com in the automated Chrome browser (scan the QR code) and re-run the command
- Refresh/sync the cookie session used by the CLI (re-export cookies from a logged-in browser)
- Check the account in a normal browser: if you were logged out or restricted, recover the login first
- 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
- Re-login (QR scan) whenever the session is refreshed or expired
- Persist and reuse a logged-in Chrome profile for automation
- Detect AuthRequiredError early and run the login flow automatically
- Avoid running duplicate sessions that invalidate each other's cookies
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
- Waiting for Bilibili session cookies
- bilibili.com
- Chaoxing session cookies missing
- Claude sessionKey cookie missing
- Claude session incomplete — ajs_user_id cookie missing
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/a7f071abf171331e.
Report an issue: GitHub.