DIYgod/RSSHub · error · ConfigNotFoundError

缺少知乎用户登录后的 Cookie 值

Error message

缺少知乎用户登录后的 Cookie 值

What it means

A `ConfigNotFoundError` thrown by the Zhihu "following timeline" (用户关注时间线) route when `config.zhihu.cookies` is `undefined`. This route hits Zhihu's authenticated `/api/v3/moments` endpoint, which requires the cookie of a logged-in account, so a self-hosted RSSHub without that config cannot serve it.

Source

Thrown at lib/routes/zhihu/timeline.ts:38

        ],
        requirePuppeteer: false,
        antiCrawler: true,
        supportBT: false,
        supportPodcast: false,
        supportScihub: false,
    },
    name: '用户关注时间线',
    maintainers: ['SeanChao'],
    handler,
    description: `::: warning
用户关注动态需要登录后的 Cookie 值,所以只能自建,详情见部署页面的配置模块。
:::`,
};

async function handler(ctx) {
    const cookie = config.zhihu.cookies;
    if (cookie === undefined) {
        throw new ConfigNotFoundError('缺少知乎用户登录后的 Cookie 值');
    }
    const response = await got({
        method: 'get',
        url: 'https://www.zhihu.com/api/v3/moments',
        headers: {
            Cookie: cookie,
        },
        searchParams: {
            desktop: true,
            limit: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 15,
        },
    });
    const feeds = response.data.data;

    const urlBase = 'https://zhihu.com';
    const buildLink = (e) => {
        if (!e || !e.target || !e.target.type) {
            return '';

View on GitHub (pinned to bed535e087)

Solutions

  1. Set `ZHIHU_COOKIES` in your RSSHub environment to the full `Cookie` header string copied from a logged-in zhihu.com browser session.
  2. Restart/reload RSSHub so the config is picked up, then retry the route.
  3. Refresh the cookie periodically — Zhihu sessions expire, and a stale/empty value will eventually cause auth failures downstream.

Example fix

# before — env missing
# (ZHIHU_COOKIES not set)
# after — set in .env or shell
ZHIHU_COOKIES="z_c0=2|1:0|...; d_c0=...; _zap=..."
Defensive patterns

Strategy: validation

Validate before calling

// Before enabling the route, assert the cookie is configured
import config from '@/config';
function ensureZhihuCookie() {
    if (!config.zhihu.cookies) {
        throw new Error('Set ZHIHU_COOKIES env var to a logged-in zhihu.com cookie string before using this route.');
    }
}

Type guard

function hasZhihuCookie(): boolean {
    return typeof config.zhihu.cookies === 'string' && config.zhihu.cookies.length > 0;
}

Prevention

When it happens

Trigger: The route is invoked on an RSSHub instance where the `ZHIHU_COOKIES` environment variable / config key was never set. The handler reads `config.zhihu.cookies`, finds it undefined, and aborts before any network call.

Common situations: Operator deploys RSSHub but skips the Zhihu cookie config; the env var name is misspelled; the cookie was set in a different config layer (e.g. `.env` not loaded); the cookie expired and was removed rather than refreshed.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/68b26dce41883309. Report an issue: GitHub.