{"record":{"id":"69b26c583675d462","repo":"jackwener/OpenCLI","slug":"www-zhihu-com-69b26c","errorCode":null,"errorMessage":"www.zhihu.com","messagePattern":"www\\.zhihu\\.com","errorType":"error_code","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/zhihu/user.js","lineNumber":37,"sourceCode":"    func: async (page, kwargs) => {\n        const slug = parseZhihuUser(kwargs.user);\n        await page.goto('https://www.zhihu.com');\n        const apiUrl = `https://www.zhihu.com/api/v4/members/${encodeURIComponent(slug)}?include=${encodeURIComponent(INCLUDE)}`;\n        const data = unwrapEvaluateResult(await page.evaluate(`\n      (async () => {\n        try {\n          const r = await fetch(${JSON.stringify(apiUrl)}, { credentials: 'include' });\n          if (!r.ok) return { __httpError: r.status };\n          return await r.json();\n        } catch (err) {\n          return { __fetchError: err?.message || String(err) };\n        }\n      })()\n    `));\n        if (!data || typeof data !== 'object' || Array.isArray(data) || data.__httpError || data.__fetchError) {\n            const status = data?.__httpError;\n            if (status === 401 || status === 403) {\n                throw new AuthRequiredError('www.zhihu.com', 'Failed to fetch Zhihu user profile');\n            }\n            if (status === 404) {\n                throw new EmptyResultError('zhihu user', `No Zhihu user was found for ${slug}.`);\n            }\n            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');\n        }\n        if (!data.url_token || !data.id || !data.name) {\n            throw new CommandExecutionError('Zhihu user response missing identity fields', 'Zhihu may have changed its API shape');\n        }\n        return [{\n            url_token: String(data.url_token || ''),\n            name: String(data.name || ''),\n            headline: String(data.headline || ''),\n            followers: data.follower_count ?? 0,\n            following: data.following_count ?? 0,\n            answers: data.answer_count ?? 0,\n            articles: data.articles_count ?? 0,\n            voteup: data.voteup_count ?? 0,","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/user.js#L19-L55","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before calling: verify an authenticated session exists\nconst hasSession = document.cookie.split(';').some(c => c.trim().startsWith('z_c0='));\nif (!hasSession) throw new Error('Zhihu login required: z_c0 cookie missing');","typeGuard":null,"tryCatchPattern":"try {\n  const profile = await fetchZhihuUser(slug);\n} catch (e) {\n  if (e.name === 'AuthRequiredError') {\n    await refreshZhihuLogin(); // re-login to obtain fresh cookies\n    return fetchZhihuUser(slug);\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["auth","zhihu","http-403"],"backgroundTag":"auth-required-login-cookies","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}