jackwener/OpenCLI · critical · AuthRequiredError
xueqiu.com
Error message
xueqiu.com
What it means
verifyXueqiuIdentity first checks via hasXueqiuAccessToken that the browser session has a non-empty `xq_a_token` cookie for xueqiu.com. If absent, it throws AuthRequiredError('xueqiu.com', 'Xueqiu xq_a_token cookie missing — anonymous'), meaning the session is anonymous and xueqiu APIs will reject or degrade requests.
Source
Thrown at clis/xueqiu/auth.js:11
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';
async function hasXueqiuAccessToken(page) {
const cookies = await page.getCookies({ url: 'https://xueqiu.com' });
return cookies.some(c => c.name === 'xq_a_token' && c.value);
}
async function verifyXueqiuIdentity(page) {
if (!await hasXueqiuAccessToken(page)) {
throw new AuthRequiredError('xueqiu.com', 'Xueqiu xq_a_token cookie missing — anonymous');
}
await page.goto('https://xueqiu.com/');
await page.wait(2);
const probe = await page.evaluate(`(async () => {
try {
const res = await fetch(
'https://stock.xueqiu.com/v5/stock/portfolio/stock/list.json?size=1&category=1&pid=-1',
{ credentials: 'include' },
);
if (res.status === 403) {
return { kind: 'http', httpStatus: 403, detail: 'xueqiu stock API 403 — anti-bot / rate limit' };
}
if (!res.ok) return { kind: 'http', httpStatus: res.status };
const d = await res.json();
if (d?.error_code === 60201) {
return { kind: 'auth', detail: 'xueqiu portfolio API error_code 60201 用户id无效 — anonymous' };
}
if (d?.error_code) {View on GitHub (pinned to 49907e53dc)
Solutions
- Log in to xueqiu.com in the automated browser session to obtain xq_a_token
- Point the tool at the browser profile that already holds the cookie
- Clear and redo the login flow so cookies are freshly set
- Verify getCookies({url:'https://xueqiu.com'}) actually returns the cookie (domain/path scoping)
Example fix
// before (anonymous session)
await page.getCookies({ url: 'https://xueqiu.com' }); // no xq_a_token -> throw
// after
await page.login('xueqiu.com'); // complete login first
await page.getCookies({ url: 'https://xueqiu.com' }); // xq_a_token present Defensive patterns
Strategy: validation
Validate before calling
const cookies = await page.getCookies({ url: 'https://xueqiu.com' });
if (!cookies.some(c => c.name === 'xq_a_token' && c.value)) throw new Error('Login to xueqiu.com first: xq_a_token missing'); Type guard
const hasXqToken = (cookies) => Array.isArray(cookies) && cookies.some(c => c.name === 'xq_a_token' && Boolean(c.value));
Try / catch
try { await verifyXueqiuIdentity(page); } catch (e) { if (String(e).includes('xq_a_token')) { console.error('Run the xueqiu login flow, then retry'); process.exitCode = 1; } else throw e; } Prevention
- Always run the login flow before authenticated xueqiu commands
- Verify the xq_a_token cookie exists before API probes
- Use a persistent browser profile so cookies survive restarts
- Re-check cookies after long idle periods (expiry)
When it happens
Trigger: Running the auth flow in a browser context that was never logged into xueqiu.com, after cookies were cleared/expired, with a profile pointing at the wrong user-data dir, or when cookie retrieval is scoped to the wrong URL so the token isn't visible.
Common situations: Fresh automation profiles, token expiry after xueqiu rotates xq_a_token, headless sessions where login was never completed, or corporate proxies stripping cookies.
Related errors
- 1point3acres Discuz *_auth cookie missing
- Waiting for Bilibili session cookies
- Bilibili ${label} API requires login or permission: ${messag
- Bilibili ${label} API requires login or permission: ${messag
- bilibili.com
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5b6921b2dd38eaa8.
Report an issue: GitHub.