DIYgod/RSSHub · error · Error

小红书未返回用户数据,请稍后再试: ${JSON.stringify(userPageData.result)}

Error message

小红书未返回用户数据,请稍后再试: ${JSON.stringify(userPageData.result)}

What it means

Thrown by getUser in the Xiaohongshu (小红书) route after Playwright loads a user profile page and parses window.__INITIAL_STATE__. The code expects initialState.user.userPageData to carry a basicInfo object; when that field is absent the user payload is considered invalid and the route aborts, embedding userPageData.result in the message for diagnostics. It is a raw Error (not a typed RSSHub error), so the message text is the only discriminator.

Source

Thrown at lib/routes/xiaohongshu/util.ts:115

                        const response = await page.waitForResponse(
                            (res) => {
                                const req = res.request();
                                return req.url().includes('/api/sns/web/v2/note/collect/page') && req.method() === 'GET' && req.resourceType() === 'xhr';
                            },
                            { timeout: 5000 }
                        );
                        collect = await response.json();
                    } catch {
                        //
                    }
                }

                let { userPageData, notes } = initialState.user;
                userPageData = userPageData._rawValue || userPageData;
                notes = notes._rawValue || notes;

                if (!userPageData.basicInfo) {
                    throw new Error(`小红书未返回用户数据,请稍后再试: ${JSON.stringify(userPageData.result)}`);
                }

                return { userPageData, notes, collect };
            } finally {
                await destroy();
            }
        },
        config.cache.routeExpire,
        false
    );

const getBoard = (url, cache) =>
    cache.tryGet(
        url,
        async () => {
            // Use proxy if configured
            if (config.xiaohongshu.proxy) {
                const res = await fetchWithProxy(url);

View on GitHub (pinned to bed535e087)

Solutions

  1. Set or refresh XIAOHONGSHU_COOKIE in the instance config with a freshly logged-in browser cookie and retry.
  2. Open the same user URL in a browser to confirm the account exists and is public; if XHS shows a login wall, the cookie is the cause.
  3. Retry after a few minutes — XHS risk-control often throttles temporarily and recovers.
  4. If persistent, inspect the embedded JSON.stringify(userPageData.result) in the message to see whether XHS changed the payload shape, then update the basicInfo check in lib/routes/xiaohongshu/util.ts:114.
  5. Run behind a proxy (config.xiaohongshu.proxy) if the deploy IP is geo-blocked or rate-limited by XHS.

Example fix

// before
if (!userPageData.basicInfo) {
    throw new Error(`小红书未返回用户数据,请稍后再试: ${JSON.stringify(userPageData.result)}`);
}

// after — surface the anti-bot/login causes distinctly and keep the raw payload for debugging
if (!userPageData?.basicInfo) {
    const hint = userPageData?.result ? `小红书返回异常: ${JSON.stringify(userPageData.result)}` : '小红书未返回用户数据,可能是 Cookie 过期或账号不存在';
    throw new Error(hint);
}
Defensive patterns

Strategy: retry

Validate before calling

// Before calling getUser, confirm the user id looks like an XHS id and the cookie is set
import { config } from '@/config';
function preflightXhsUser(userId: string) {
    if (!userId || /[\\/?#]/.test(userId)) {
        throw new Error(`Suspicious XHS user id: ${userId}`);
    }
    if (!config.xiaohongshu.cookie) {
        throw new Error('XIAOHONGSHU_COOKIE is not set; getUser will likely fail with missing basicInfo');
    }
}

Type guard

function hasBasicInfo(userPageData: unknown): userPageData is { basicInfo: Record<string, unknown> } {
    return typeof userPageData === 'object' && userPageData !== null && 'basicInfo' in userPageData && typeof (userPageData as any).basicInfo === 'object';
}

Try / catch

// XHS risk-control is transient — retry a couple of times before surfacing
let lastErr;
for (let attempt = 0; attempt < 3; attempt++) {
    try {
        return await getUser(url, cache);
    } catch (e) {
        lastErr = e;
        if (!/未返回用户数据/.test(e.message)) throw e;
        await new Promise((r) => setTimeout(r, (attempt + 1) * 2000));
    }
}
throw lastErr;

Prevention

When it happens

Trigger: Playwright navigates to an xiaohongshu.com user page, the page passes the captcha/lock-icon check, extractInitialState succeeds, but initialState.user.userPageData has no basicInfo property (e.g. userPageData is {} or only carries a redirect/error result). Happens when the user_id does not exist, the account was banned/private, XHS returned a login-required or risk-control interstitial that still rendered __INITIAL_STATE__, or the configured cookie expired so XHS omitted the user section.

Common situations: Cookie (XIAOHONGSHU_COOKIE) not set or expired; a stale/incorrect user id in the route path; XHS tightened anti-bot and returns a partial state instead of the captcha box that line 87 checks; XHS shipped a page redesign renaming basicInfo.

Related errors


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