jackwener/OpenCLI · error · AuthRequiredError
www.zhihu.com
Error message
www.zhihu.com
What it means
This AuthRequiredError is thrown by requireSearchPayload when the Zhihu search response carries __httpError with status 401 or 403, meaning Zhihu refused the request because the session lacks valid authentication. The 'www.zhihu.com' message is the host marker for the auth-requirement error; the remedy is signing in via the connected Chrome profile.
Source
Thrown at clis/zhihu/search.js:83
throw new ArgumentError(`zhihu search --type must be one of: ${TYPES.join(', ')}`, 'Example: opencli zhihu search codex --type answer');
}
return type;
}
function unwrapEvaluateResult(payload) {
if (payload && typeof payload === 'object' && 'data' in payload && 'session' in payload) return payload.data;
return payload;
}
function requireSearchPayload(data, url) {
const payload = unwrapEvaluateResult(data);
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
throw new CommandExecutionError('Zhihu search returned malformed payload');
}
if (payload.__httpError) {
const status = payload.__httpError;
if (status === 401 || status === 403) {
throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch search results from Zhihu');
}
throw new CommandExecutionError(`Zhihu search request failed${status ? ` (HTTP ${status})` : ''}`, 'Try again later or rerun with -v for more detail');
}
if (payload.__fetchError) {
throw new CommandExecutionError('Zhihu search request failed', String(payload.__fetchError));
}
if (!Array.isArray(payload.data)) {
throw new CommandExecutionError('Zhihu search returned malformed data list', `URL: ${url}`);
}
if (!payload.paging || typeof payload.paging !== 'object') {
throw new CommandExecutionError('Zhihu search returned malformed paging data', `URL: ${url}`);
}
return payload;
}
function normalizeResultItem(item) {
if (!item || typeof item !== 'object' || item.type !== 'search_result' || !item.object || typeof item.object !== 'object') {
return null;View on GitHub (pinned to 49907e53dc)
Solutions
- Open www.zhihu.com in the connected Chrome profile and log in (scan QR if needed), then rerun the search
- Clear the risk-control state by browsing manually once, then retry
- If recently logged in but still 401/403, check for cookie-clearing extensions or privacy settings
- Retry later if Zhihu is enforcing temporary login walls on search
Example fix
// before: retrying blindly on auth error
await searchZhihu(q);
// after
catch (err) {
if (err instanceof AuthRequiredError) {
console.error('Log in to www.zhihu.com in the connected Chrome profile, then rerun.');
return;
}
throw err;
} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-flight: check the session is authenticated
const me = await bridge.evaluate("fetch('https://www.zhihu.com/api/v4/me').then(r => r.status)");
if (me === 401) throw new Error('Log in to www.zhihu.com in the connected Chrome profile first'); Type guard
function isAuthRequiredError(err) {
return err instanceof AuthRequiredError || (err instanceof Error && err.message.includes('www.zhihu.com'));
} Try / catch
try {
const results = await searchZhihu(q);
} catch (err) {
if (isAuthRequiredError(err)) {
console.error('Zhihu session expired. Sign in at www.zhihu.com in the connected Chrome profile, then rerun.');
return null;
}
throw err;
} Prevention
- Periodically confirm you are still logged in on www.zhihu.com in the automation profile
- Keep cookies persistent by using a dedicated (non-incognito) Chrome profile
- Disable cookie-clearing extensions or 'clear on exit' browser settings
- Re-login proactively before long batch jobs
When it happens
Trigger: Running zhihu search while logged out (or with expired Zhihu cookies) and the in-page fetch of the search API returns HTTP 401/403, surfacing as payload.__httpError.
Common situations: Zhihu session expired after days of inactivity; using a clean/incognito Chrome profile with no login; Zhihu now requiring login for search; cookies cleared by browser hygiene tooling.
Related errors
- Zhihu /api/v4/me returned HTTP ${status} — anonymous
- LinkedIn Sales Navigator API auth failed (HTTP ' + (result.s
- Manus /api/auth/session HTTP ${r.status}
- Bilibili creator-center login is required: ${detail}
- bbs.hupu.com
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5aec0af6a0496063.
Report an issue: GitHub.