jackwener/OpenCLI · error · AuthRequiredError

请在浏览器里用千问 APP 扫码登录 qianwen.com 后再重试。

Error message

请在浏览器里用千问 APP 扫码登录 qianwen.com 后再重试。

What it means

This is the Qianwen CLI's AuthRequiredError (built by authRequired() in clis/qwen/utils.js:22). It is thrown when the automation cannot prove the browser session is logged into qianwen.com, because the entire qwen workflow (sending prompts, reading replies) depends on an authenticated session. The message instructs the user to scan a QR code with the Qianwen mobile app to log in before retrying.

Source

Thrown at clis/qwen/ask.js:68

        await ensureOnQianwen(page);
        await dismissLoginModal(page);

        if (startFresh) {
            await startNewChat(page);
            await dismissLoginModal(page);
        }

        if (useThink) await setFeatureToggle(page, 'think', true);
        if (useResearch) await setFeatureToggle(page, 'research', true);

        // Anchor on the visible transcript BEFORE sending so waitForAnswer can
        // bind the reply to the newly sent prompt instead of an older answer.
        const baselineAnchor = await getBaselineChatAnchor(page);

        const send = await sendMessage(page, prompt);
        if (!send?.ok) {
            if (await hasLoginGate(page)) throw authRequired();
            throw new CommandExecutionError(send?.reason || 'Failed to send Qianwen prompt');
        }

        const result = await waitForAnswer(page, prompt, timeout, baselineAnchor);
        if (result.status === 'auth_required') throw authRequired();
        if (result.status === 'timeout') {
            throw new TimeoutError('qianwen ask', timeout, 'No Qianwen reply observed before timeout. Retry with --timeout increased.');
        }
        const assistant = result.assistant;
        if (!assistant) {
            throw new CommandExecutionError('No assistant reply found in Qianwen chat.');
        }
        const answer = wantMarkdown && assistant.html
            ? (bubbleHtmlToMarkdown(assistant.html) || assistant.text)
            : assistant.text;
        return [
            { Role: 'User', Text: prompt },
            { Role: 'Assistant', Text: answer },

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open qianwen.com in the automation browser and log in by scanning the QR code with the Qianwen mobile app, then rerun the command
  2. Persist the browser user-data/profile directory so the login cookie survives across runs
  3. Re-check hasLoginGate detection: if you ARE logged in but still see this, the login-gate selector may have changed and needs updating
  4. Rerun with a longer timeout in case the auth_required status came from a slow page load misdetected as a gate

Example fix

// before
await qwenAsk(prompt); // throws AuthRequiredError on expired session
// after
try {
  await qwenAsk(prompt);
} catch (e) {
  if (e.code === 'AUTH_REQUIRED') {
    await loginQianwenViaQr(browser); // interactive QR login once, persisted profile
    await qwenAsk(prompt);
  }
}
Defensive patterns

Strategy: try-catch

Validate before calling

const url = await page.evaluate('window.location.href').catch(() => '');
if (!url.includes('qianwen.com')) throw new Error('Not on qianwen.com — login first');

Type guard

function isAuthError(e) { return e && (e.code === 'AUTH_REQUIRED' || /扫码登录/.test(String(e.message))); }

Try / catch

try {
  await qwenAsk(prompt);
} catch (e) {
  if (isAuthError(e)) {
    await interactiveQianwenQrLogin();
    return qwenAsk(prompt);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `qwen ask` when: (1) hasLoginGate(page) detects a login wall/modal after sendMessage fails to deliver the prompt, or (2) waitForAnswer reports result.status === 'auth_required' — i.e. the session was logged out or expired mid-conversation.

Common situations: The shared browser profile has no Qianwen login cookie or it expired; qianwen.com rotated its login wall so the session was invalidated; a fresh/incognito automation browser was used without prior manual login; a CAPTCHA or re-auth modal appeared mid-run.

Related errors


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