jackwener/OpenCLI · error · AuthRequiredError
Weibo SUB / SUBP cookies missing
Error message
Weibo SUB / SUBP cookies missing
What it means
verifyWeiboIdentity first checks for Weibo's SUB/SUBP session cookies via hasWeiboSessionCookie. If they are absent, it throws AuthRequiredError('weibo.com', 'Weibo SUB / SUBP cookies missing') because there is no logged-in session to verify identity against.
Source
Thrown at clis/weibo/auth.js:37
if (res.status === 401 || res.status === 403) {
return { kind: 'auth', detail: 'Weibo /ajax/profile/info HTTP ' + res.status };
}
if (!res.ok) return { kind: 'http', httpStatus: res.status };
const d = await res.json();
const user = d && d.data && d.data.user;
if (!user || !user.id) {
return { kind: 'auth', detail: 'Weibo /ajax/profile/info returned no user — anonymous' };
}
return { ok: true, user_id: String(user.id), screen_name: String(user.screen_name || ''), profile_url: String(user.profile_url || '') };
} catch (e) {
return { kind: 'exception', detail: String(e && e.message || e) };
}
})()`;
}
async function verifyWeiboIdentity(page) {
if (!await hasWeiboSessionCookie(page)) {
throw new AuthRequiredError('weibo.com', 'Weibo SUB / SUBP cookies missing');
}
await page.goto('https://weibo.com/');
await page.wait(3);
// getSelfUid throws AuthRequiredError when no logged-in uid can be resolved.
const uid = await getSelfUid(page);
if (typeof uid !== 'string' || !uid.trim()) {
throw new CommandExecutionError('Weibo uid resolver returned a malformed uid');
}
const result = unwrapEvaluateResult(await page.evaluate(buildWeiboIdentityProbe(uid)));
if (result?.kind === 'auth') throw new AuthRequiredError('weibo.com', result.detail);
if (result?.kind === 'http') throw new CommandExecutionError(`HTTP ${result.httpStatus} from /ajax/profile/info`);
if (result?.kind === 'exception') throw new CommandExecutionError(`Weibo whoami failed: ${result.detail}`);
if (!result || Array.isArray(result) || typeof result !== 'object') {
throw new CommandExecutionError('Weibo whoami returned malformed probe payload');
}
if (!result?.ok) throw new CommandExecutionError(`Unexpected Weibo probe: ${JSON.stringify(result)}`);
if (!result.user_id) throw new CommandExecutionError('Weibo whoami returned no user id');
return { user_id: result.user_id, screen_name: result.screen_name, profile_url: result.profile_url };View on GitHub (pinned to 49907e53dc)
Solutions
- Log in to weibo.com in the controlled browser (or run the weibo login command) before publishing
- Use a persistent session profile so cookies survive between runs
- Check cookie names/domains in hasWeiboSessionCookie still match Weibo's current session cookies
- Re-run after clearing corrupted cookie state and logging in fresh
Example fix
// before await publish(page, opts); // page has no session // after const auth = await checkWeiboAuth(page); if (!auth.ok) await runWeiboLogin(page); // sets SUB/SUBP cookies await publish(page, opts);
Defensive patterns
Strategy: validation
Validate before calling
const cookies = await page.getCookies?.() ?? [];
const hasSession = cookies.some(c => ['SUB','SUBP'].includes(c.name) && c.value);
if (!hasSession) throw new Error('Log in to weibo.com first — SUB/SUBP cookies missing'); Type guard
function hasWeiboCookies(cookieList) {
return Array.isArray(cookieList) &&
['SUB', 'SUBP'].every(name => cookieList.some(c => c.name === name && !!c.value));
} Try / catch
try {
await verifyWeiboIdentity(page);
} catch (e) {
if (e instanceof AuthRequiredError && /SUB \/ SUBP/.test(e.message)) {
console.error('No Weibo session — run the login flow, then retry.');
} else throw e;
} Prevention
- Log in to weibo.com before running publish commands
- Use a persistent browser profile so cookies persist
- Re-login when sessions expire rather than reusing stale profiles
- Verify cookie presence cheaply before invoking the full flow
When it happens
Trigger: hasWeiboSessionCookie(page) resolves false: cookies were never set, expired, cleared, or the page belongs to a different browser context/profile.
Common situations: Running against a fresh/incognito browser profile; Weibo invalidated old session cookies; cookies stored under a different domain variant (weibo.cn vs weibo.com); user logged out between commands.
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/287ce24f47981202.
Report an issue: GitHub.