jackwener/OpenCLI · error · AuthRequiredError

未登录,请先在浏览器中登录贝壳找房

Error message

未登录,请先在浏览器中登录贝壳找房

What it means

assertNotBlocked checks the page title for login prompts (请登录, 立即登录, 扫码登录, etc.). If the page effectively demands login, it throws AuthRequiredError instructing the user to sign into 贝壳找房 (ke.com) in the browser. It is thrown even when a session cookie nominally exists but the site still renders a login-gated page.

Source

Thrown at clis/ke/utils.js:60

        return { href: '', title: '', body_text: '' };
    }
    return {
        href: cleanText(result.href),
        title: cleanText(result.title),
        body_text: cleanText(result.body_text),
    };
}

export function assertNotBlocked(state) {
    const { href, title, body_text } = state;
    if (href.includes('hip.ke.com/captcha') || href.includes('/captcha')) {
        throw new AuthRequiredError('ke.com', '触发了验证码,请先在浏览器中完成验证');
    }
    if (CAPTCHA_TEXT_PATTERNS.some(p => title.includes(p) || body_text.includes(p))) {
        throw new AuthRequiredError('ke.com', '触发了验证码,请先在浏览器中完成滑块验证');
    }
    if (LOGIN_TEXT_PATTERNS.some(p => title.includes(p))) {
        throw new AuthRequiredError('ke.com', '未登录,请先在浏览器中登录贝壳找房');
    }
}

export async function gotoKe(page, url) {
    await page.goto(url, { settleMs: 2500 });
    await page.wait(2);
    const state = await readPageState(page);
    assertNotBlocked(state);
    return state;
}

/**
 * Fetch a ke.com JSON API from inside the browser context (credentials included).
 */
export async function fetchKeJson(page, url) {
    const result = await page.evaluate(`(async () => {
    const res = await fetch(${JSON.stringify(url)}, { credentials: 'include' });
    if (!res.ok) return { __keErr: res.status };

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the ke auth login flow and log in via the browser, then retry
  2. Verify session validity with the ke auth verify command before batch runs
  3. If a public page falsely matches a login pattern in its title, treat it as a selector false-positive and adjust LOGIN_TEXT_PATTERNS in clis/ke/utils.js

Example fix

// before
$ opencli ke ershoufang search 四合院  # 未登录,请先在浏览器中登录贝壳找房
// after
$ opencli ke auth login && opencli ke ershoufang search 四合院
Defensive patterns

Strategy: try-catch

Validate before calling

const state = await readPageState(page);
const loginWords = ['请登录','登录后','账号登录','手机登录','立即登录','扫码登录'];
if (loginWords.some(w => state.title.includes(w))) {
  console.log('Login wall detected — run `opencli ke auth login` first');
  process.exit(2);
}

Try / catch

import { AuthRequiredError } from '@jackwener/opencli/errors';
try {
  await gotoKe(page, url);
} catch (e) {
  if (e instanceof AuthRequiredError && e.message.includes('未登录')) {
    console.error('Please log into ke.com in the managed browser, then retry.');
    process.exitCode = 2;
  } else throw e;
}

Prevention

When it happens

Trigger: Visiting a login-required ke.com page anonymously; the lianjia_token cookie expired so the server renders a login wall; the target page inherently requires authentication (e.g. saved favorites, agent contact).

Common situations: Token TTL expired overnight; user logged out elsewhere, invalidating the session; browsing public pages that happen to show a login banner in the title.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/98972e93d4b0c1ea. Report an issue: GitHub.