{"record":{"id":"46948f1861d66184","repo":"DIYgod/RSSHub","slug":"zhihu-failed-to-obtain-a-guest-d-c0-cookie","errorCode":null,"errorMessage":"zhihu: failed to obtain a guest d_c0 cookie","messagePattern":"zhihu: failed to obtain a guest d_c0 cookie","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/routes/zhihu/utils.ts","lineNumber":113,"sourceCode":"    // `__zse_ck` is checked against the user-agent that generated it.\n    const ua = generateHeaders()['user-agent'];\n    const headers = { 'user-agent': ua };\n\n    let dc0 = configuredDc0;\n    if (!dc0) {\n        const seed = await ofetch.raw('https://www.zhihu.com/explore', {\n            headers,\n            redirect: 'manual',\n            ignoreResponseError: true,\n        });\n        dc0 =\n            (seed.headers.getSetCookie?.() ?? [])\n                .find((line) => line.startsWith('d_c0='))\n                ?.split(';', 1)[0]\n                .slice('d_c0='.length) || '';\n    }\n    if (!dc0) {\n        throw new Error('zhihu: failed to obtain a guest d_c0 cookie');\n    }\n\n    const challenge = await ofetch.raw(`https://www.zhihu.com${apiPath}`, {\n        headers: {\n            ...headers,\n            cookie: `d_c0=${dc0}; __zse_ck=005_x-x`,\n            referer: url,\n            'x-requested-with': 'fetch',\n        },\n        ignoreResponseError: true,\n    });\n    const html = challenge._data as string;\n    const meta = html.match(/id=\"zh-zse-ck\"[^>]*content=\"([^\"]*)\"/)?.[1];\n    const hash = html.match(/zse-ck\\/v4\\/([a-f0-9]+)\\.js/)?.[1];\n    if (!meta || !hash) {\n        throw new Error('zhihu: challenge page did not contain an URL to __zse_ck meta/script');\n    }\n","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/zhihu/utils.ts#L95-L131","documentation":"Thrown by the Zhihu anti-bot credential generator when it cannot obtain a guest `d_c0` cookie. The flow first requests `https://www.zhihu.com/explore` (with manual redirect handling) and scans the `Set-Cookie` headers for a `d_c0=` entry; if none is present, the whole `__zse_ck` challenge pipeline cannot proceed and this error is raised.","triggerScenarios":"Zhihu does not return a `d_c0` cookie on the `/explore` seed request — because the request was blocked, rate-limited, geo-restricted, or the response was an interstitial/captcha page rather than a normal one. A configured `config.zhihu.cookies` value bypasses this path entirely.","commonSituations":"RSSHub runs from an IP/datacenter Zhihu flags as suspicious; Zhihu tightens its bot detection and stops issuing guest cookies; a transient network error returns a non-HTML body; `getSetCookie` is unsupported by the runtime fetch layer so the cookie list looks empty.","solutions":["Configure `config.zhihu.cookies` (env `ZHIHU_COOKIES`) with a real logged-in `d_c0` so the guest-seed step is skipped (`dc0 = configuredDc0`).","Retry after a short interval — guest-cookie denial is often transient (rate limit / intermittent block).","Run RSSHub from a residential/non-blocked IP or through a proxy that Zhihu does not flag.","If `getSetCookie` is undefined in your Node/fetch version, upgrade Node (it needs `Headers.getSetCookie` support) or polyfill header parsing."],"exampleFix":"# before — guest flow blocked, no d_c0\n# (no ZHIHU_COOKIES set, /explore returns no d_c0)\n# after — supply a d_c0 via config so the seed request is skipped\nZHIHU_COOKIES=\"d_c0=AAAA...\"","handlingStrategy":"retry","validationCode":"// Pre-flight: confirm /explore yields a d_c0 before depending on the guest flow\nasync function canGetGuestDc0() {\n    const r = await ofetch.raw('https://www.zhihu.com/explore', { redirect: 'manual', ignoreResponseError: true });\n    return (r.headers.getSetCookie?.() ?? []).some((l) => l.startsWith('d_c0='));\n}","typeGuard":null,"tryCatchPattern":"// Retry the guest-seed a few times; fall back to configured cookie\nasync function getDc0WithRetry(configuredDc0, attempts = 3) {\n    if (configuredDc0) return configuredDc0;\n    for (let i = 0; i < attempts; i++) {\n        try {\n            return await seedGuestDc0();\n        } catch (e) {\n            if (i === attempts - 1) throw e;\n            await wait(1000 * (i + 1));\n        }\n    }\n}","preventionTips":["Always configure ZHIHU_COOKIES with a real d_c0 so the guest-seed path is bypassed.","Run RSSHub behind a residential/proxy egress that Zhihu doesn't flag.","Ensure Node supports Headers.getSetCookie (Node >= 18.14) so the cookie list isn't silently empty."],"tags":["zhihu","anti-bot","cookie","network","retryable"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}