jackwener/OpenCLI · error · CommandExecutionError

Zhihu identity probe failed (HTTP ${status ?? 'unknown'})

Error message

Zhihu identity probe failed (HTTP ${status ?? 'unknown'})

What it means

If /api/v4/me returns an HTTP error status other than 401/403 (or the status is unknown), verifyZhihuIdentity throws CommandExecutionError 'Zhihu identity probe failed (HTTP <status>)'. It means the identity probe could not be completed — the API responded abnormally but not with a definitive 'anonymous' signal.

Source

Thrown at clis/zhihu/auth.js:34

    (async () => {
      try {
        const r = await fetch('https://www.zhihu.com/api/v4/me?include=url_token', { credentials: 'include' });
        if (!r.ok) return { __httpError: r.status };
        return await r.json();
      } catch (e) {
        return { __exception: String(e && e.message || e) };
      }
    })()
  `);
  if (data?.__exception) {
    throw new CommandExecutionError(`Zhihu whoami failed: ${data.__exception}`);
  }
  if (!data || data.__httpError) {
    const status = data?.__httpError;
    if (status === 401 || status === 403) {
      throw new AuthRequiredError('www.zhihu.com', `Zhihu /api/v4/me returned HTTP ${status} — anonymous`);
    }
    throw new CommandExecutionError(`Zhihu identity probe failed (HTTP ${status ?? 'unknown'})`);
  }
  if (!data.url_token) {
    throw new AuthRequiredError('www.zhihu.com', 'Zhihu /api/v4/me returned no url_token — anonymous session');
  }
  return {
    url_token: String(data.url_token),
    name: String(data.name ?? ''),
    uid: String(data.uid ?? data.id ?? ''),
  };
}

registerSiteAuthCommands({
  site: 'zhihu',
  domain: 'www.zhihu.com',
  loginUrl: 'https://www.zhihu.com/signin',
  columns: ['url_token', 'name', 'uid'],
  quickCheck: hasZhihuAuthCookie,
  verify: verifyZhihuIdentity,

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry after a delay, especially if the status is 429 or 5xx — these are usually transient.
  2. Check Zhihu status/availability in a normal browser to rule out a site-wide incident.
  3. Reduce request frequency if you see 429 (add delays between commands).
  4. Catch CommandExecutionError for non-auth statuses and implement backoff rather than re-login (re-login won't help for 5xx).

Example fix

// before
const me = await verifyZhihuIdentity(page); // probe failed (HTTP 500)
// after
async function verifyWithRetry(page, attempts = 3) {
  for (let i = 0; i < attempts; i++) {
    try { return await verifyZhihuIdentity(page); }
    catch (e) {
      const m = /HTTP (\d+)/.exec(e.message);
      if (m && !['401','403'].includes(m[1]) && i < attempts - 1) {
        await sleep(2000 * (i + 1)); continue;
      }
      throw e;
    }
  }
}
Defensive patterns

Strategy: retry

Type guard

function isTransientHttpError(e) { const m = /HTTP (\d+)/.exec(String(e.message)); return !!m && Number(m[1]) >= 500 || Number(m?.[1] ?? 0) === 429; }

Try / catch

try { const me = await verifyZhihuIdentity(page); } catch (e) { const m = /HTTP (\d+)/.exec(e.message); if (m && !['401','403'].includes(m[1])) { await sleep(backoff(attempt++)); return verifyZhihuIdentity(page); } throw e; }

Prevention

When it happens

Trigger: Zhihu returns 5xx server errors, 429 rate limiting, or another unexpected status from /api/v4/me; __httpError is set but falls outside the 401/403 branches, including null/undefined status.

Common situations: Zhihu server-side incidents or maintenance; aggressive scraping triggering 429; geo/network edge returning 5xx; intermittent failures right after page load.

Related errors


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