jackwener/OpenCLI · error · AuthRequiredError
www.zhihu.com
Error message
www.zhihu.com
What it means
The user command runs an in-page fetch on www.zhihu.com and inspects the returned object. If the result is missing/invalid or carries __httpError 401/403, it throws AuthRequiredError naming 'www.zhihu.com' — Zhihu rejected the request as unauthenticated/forbidden, so credentials (login cookies) are required.
Source
Thrown at clis/zhihu/user.js:37
func: async (page, kwargs) => {
const slug = parseZhihuUser(kwargs.user);
await page.goto('https://www.zhihu.com');
const apiUrl = `https://www.zhihu.com/api/v4/members/${encodeURIComponent(slug)}?include=${encodeURIComponent(INCLUDE)}`;
const data = unwrapEvaluateResult(await page.evaluate(`
(async () => {
try {
const r = await fetch(${JSON.stringify(apiUrl)}, { credentials: 'include' });
if (!r.ok) return { __httpError: r.status };
return await r.json();
} catch (err) {
return { __fetchError: err?.message || String(err) };
}
})()
`));
if (!data || typeof data !== 'object' || Array.isArray(data) || data.__httpError || data.__fetchError) {
const status = data?.__httpError;
if (status === 401 || status === 403) {
throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch Zhihu user profile');
}
if (status === 404) {
throw new EmptyResultError('zhihu user', `No Zhihu user was found for ${slug}.`);
}
throw new CommandExecutionError(status ? `Zhihu user request failed (HTTP ${status})` : 'Zhihu user request failed', data?.__fetchError ? String(data.__fetchError) : 'Try again later or rerun with -v');
}
if (!data.url_token || !data.id || !data.name) {
throw new CommandExecutionError('Zhihu user response missing identity fields', 'Zhihu may have changed its API shape');
}
return [{
url_token: String(data.url_token || ''),
name: String(data.name || ''),
headline: String(data.headline || ''),
followers: data.follower_count ?? 0,
following: data.following_count ?? 0,
answers: data.answer_count ?? 0,
articles: data.articles_count ?? 0,
voteup: data.voteup_count ?? 0,View on GitHub (pinned to 49907e53dc)
Solutions
- Re-authenticate with Zhihu (log in so fresh cookies are stored) and rerun
- Clear stale session state and log in again if cookies expired
- Retry later from a different network/IP if blocked by anti-bot
- Run with -v to inspect the underlying fetch error details
Defensive patterns
Strategy: try-catch
Validate before calling
// before calling: verify an authenticated session exists
const hasSession = document.cookie.split(';').some(c => c.trim().startsWith('z_c0='));
if (!hasSession) throw new Error('Zhihu login required: z_c0 cookie missing'); Try / catch
try {
const profile = await fetchZhihuUser(slug);
} catch (e) {
if (e.name === 'AuthRequiredError') {
await refreshZhihuLogin(); // re-login to obtain fresh cookies
return fetchZhihuUser(slug);
}
throw e;
} Prevention
- Keep Zhihu login cookies fresh; re-login when sessions expire
- Avoid high-frequency scraping from datacenter IPs
- Monitor for 401/403 and pause/backoff instead of hammering
- Run authenticated flows before scheduled jobs to validate the session
When it happens
Trigger: Fetching a Zhihu user profile when the in-page fetch receives HTTP 401 or 403: expired or missing Zhihu login cookies, IP rate-limiting/blocked by anti-bot, or a browser session that was logged out.
Common situations: Running after Zhihu invalidated stored cookies; scraping from a datacenter IP that Zhihu throttles; profile pages that require login to view; headless session not authenticated.
Related errors
- Failed to fetch Zhihu answer detail
- Failed to fetch collection data from Zhihu. Please ensure yo
- ${errorLabel} from Zhihu failed. Please ensure you are logge
- Ctrip flight API returned HTTP ${status}; complete any verif
- Gmail ${operation} returned HTTP ${status}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/69b26c583675d462.
Report an issue: GitHub.