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
- Run the taobao auth/login flow first, then retry the cart command
- Restore a valid saved cookie/storage state before invoking cart
- Catch AuthRequiredError and route to interactive login automatically
- 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
- Always verify identity (verifyTaobaoIdentity) before cart operations
- Persist and restore a valid session before batch cart jobs
- Catch AuthRequiredError centrally and funnel to the login flow
- Refresh sessions proactively; Taobao sessions expire
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
- taobao search requires a logged-in Taobao session
- hotels.ctrip.com
- vacations.ctrip.com
- guazi ${contextHint} hit an anti-bot challenge — Guazi may h
- jd cart requires a logged-in JD session
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/719e783a6610597c.
Report an issue: GitHub.