jackwener/OpenCLI · error · AuthRequiredError

taobao cart requires a logged-in Taobao session

Error message

taobao cart requires a logged-in Taobao session

What it means

The taobao cart command's page-side script signals { error: 'auth-required' } when Taobao returns a not-logged-in/cart-empty-guest response; the Node wrapper converts that into AuthRequiredError. It means cart scraping needs an authenticated Taobao session and the current browser has none.

Source

Thrown at clis/taobao/cart.js:92

            if (prev && prev.length > 2 && prev.length < 30 && !prev.match(/^(删除|\\d|¥|¥|券|退|满|超)/)) {
              shop = prev;
            }
          }

          results.push({
            index: results.length + 1,
            title: title.slice(0, 80),
            price,
            spec,
            shop,
          });
          if (results.length >= ${limit}) break;
        }
        return { results };
      })()
    `);
        if (data?.error === 'auth-required') {
            throw new AuthRequiredError('taobao cart requires a logged-in Taobao session');
        }
        return Array.isArray(data?.results) ? data.results : [];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the taobao auth/login flow first, then retry the cart command
  2. Restore a valid saved cookie/storage state before invoking cart
  3. Catch AuthRequiredError and route to interactive login automatically
  4. Verify session with verifyTaobaoIdentity before scraping cart

Example fix

// before
const items = await taobaoCart(page, { limit });
// after
try {
  const items = await taobaoCart(page, { limit });
} catch (e) {
  if (e instanceof AuthRequiredError) {
    await taobaoLogin(page);
    return taobaoCart(page, { limit });
  }
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!(await hasTaobaoSessionCookie(page))) {
  throw new Error('Login to Taobao before fetching cart');
}

Type guard

function isAuthRequiredError(e) {
  return e instanceof AuthRequiredError || /logged-in Taobao session/.test(String(e?.message));
}

Try / catch

try {
  const cart = await taobaoCart(page, { limit });
} catch (e) {
  if (isAuthRequiredError(e)) {
    await taobaoLogin(page);
    return taobaoCart(page, { limit });
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the taobao cart command (fetching cart items via in-page evaluate) when the page's data indicates a guest session — Taobao redirects or embeds an auth-required marker instead of cart contents.

Common situations: Cart queried before login; session expired mid-session; cookies restored incompletely (missing cookie2/tracknick); anti-bot interstitial replacing the cart page.

Related errors


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