jackwener/OpenCLI · error · AuthRequiredError
www.zhihu.com
Error message
www.zhihu.com
What it means
AuthRequiredError raised with host 'www.zhihu.com' when the comment fetch indicates an authentication problem: HTTP 401/403, errorCode 40353, or payload.__needLogin. The library signals that valid Zhihu login credentials in the connected Chrome profile are required before the command can succeed.
Source
Thrown at clis/zhihu/answer-comments-helpers.js:75
});
const payload = unwrapEvaluateResult(evaluated);
if (payload?.__malformedJson) {
throw new CommandExecutionError(`Zhihu ${label} returned malformed JSON: ${payload.__malformedJson}`);
}
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
throw new CommandExecutionError(`Zhihu ${label} returned a malformed payload`);
}
const status = payload.__httpStatus;
const code = String(payload.__errorCode || '');
if (status >= 400 || code || payload.__errorMessage || payload.__needLogin) {
if (code === '40362') {
throw new CommandExecutionError(
`Zhihu risk control blocked ${label} (40362): ${payload.__errorMessage || 'abnormal request'}`,
'Open the answer in the connected Chrome profile and retry later.',
);
}
if (status === 401 || status === 403 || code === '40353' || payload.__needLogin) {
throw new AuthRequiredError('www.zhihu.com', `Failed to fetch Zhihu ${label}`);
}
if (status === 404 && notFoundDetail) throw new EmptyResultError('zhihu answer-comments', notFoundDetail);
if (status >= 400) throw new CommandExecutionError(`Zhihu ${label} request failed (HTTP ${status})`);
throw new CommandExecutionError(`Zhihu ${label} returned an error payload: ${payload.__errorMessage || code}`);
}
if (!Array.isArray(payload.data) || !payload.paging || typeof payload.paging !== 'object') {
throw new CommandExecutionError(`Zhihu ${label} returned a malformed payload`);
}
if (typeof payload.paging.is_end !== 'boolean') {
throw new CommandExecutionError(`Zhihu ${label} returned malformed paging state`);
}
return payload;
}
function describeComment(comment, role, expectedRootId = '') {
if (!comment || typeof comment !== 'object' || Array.isArray(comment)) {
throw new CommandExecutionError(`Zhihu answer comments contained a malformed ${role} row`);
}
const id = commentId(comment.id);View on GitHub (pinned to 49907e53dc)
Solutions
- Open www.zhihu.com in the connected Chrome profile and log in, then rerun the command
- Refresh the profile's session cookies (re-login) if it was previously authenticated
- Check that the content is not inherently login-only (e.g. restricted answers)
- Use a profile with an active Zhihu account rather than a fresh one
Example fix
// before
await cli('--answer-url', url); // fails with AuthRequiredError on stale profile
// after
// precondition: ensure login first
if (!(await isZhihuLoggedIn(profile))) await openBrowserAndLogin('https://www.zhihu.com/signin');
await cli('--answer-url', url); Defensive patterns
Strategy: try-catch
Validate before calling
const cookies = await profileCookies(); if (!cookies.some(c => c.name === 'z_c0' && c.domain.includes('zhihu.com'))) throw new Error('Zhihu session missing — log in first'); Type guard
function isAuthError(e){ return e instanceof AuthRequiredError || /401|403|40353|needLogin/i.test(String(e.message)); } Try / catch
try { await fetchCommentPage(url); } catch (e) { if (isAuthError(e)) { await promptUserToLogin('https://www.zhihu.com'); return fetchCommentPage(url); } throw e; } Prevention
- Verify a z_c0 session cookie exists in the profile before running
- Re-login periodically; sessions expire
- Check content availability anonymously if 403 persists after login
- Avoid cookie-clearing browser automation between runs
When it happens
Trigger: The comment endpoint returned status 401 or 403, or __errorCode '40353', or __needLogin was set — Zhihu says the session is not authenticated (or no longer valid) for this resource.
Common situations: Chrome profile logged out of Zhihu; session cookie expired; fetching members-only or otherwise restricted content anonymously; profile cookies cleared by browser cleanup.
Related errors
- ${probe.detail}
- 获取抖音上传授权失败: ${message}
- weibo.com
- Please log in to the WeChat Official Account platform and re
- 请先在共享 Chrome 完成 1688 登录/验证,再重试(${action})
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/bdaf41c8c5203d24.
Report an issue: GitHub.