jackwener/OpenCLI · error · AuthRequiredError
dianping.com
Error message
dianping.com
What it means
AuthRequiredError thrown by verifyDianpingIdentity when the browser context has no `dper` session cookie for www.dianping.com. Dianping requires this cookie to authenticate requests; without it any member page access will bounce to the login page. The library checks the cookie up-front to fail fast with a clear auth message.
Source
Thrown at clis/dianping/auth.js:11
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';
async function hasDianpingSessionCookie(page) {
const cookies = await page.getCookies({ url: 'https://www.dianping.com' });
return cookies.some(c => c.name === 'dper' && c.value);
}
async function verifyDianpingIdentity(page) {
if (!await hasDianpingSessionCookie(page)) {
throw new AuthRequiredError('dianping.com', 'Dianping dper cookie missing');
}
await page.goto('https://www.dianping.com/member/myinformation');
await page.wait(2);
const finalUrl = await page.evaluate(`location.href`);
if (/account\.dianping\.com\/(pc)?login/.test(String(finalUrl || ''))) {
throw new AuthRequiredError('dianping.com', `Dianping member page redirected to login: ${finalUrl}`);
}
const info = await page.evaluate(`
(() => {
const nicknameEl = document.querySelector('.user-name, .username, .nickname, .user-info .name');
const nickname = (nicknameEl?.textContent || '').trim();
const profileLink = Array.from(document.querySelectorAll('a[href*="/member/"]'))
.map(a => a.getAttribute('href') || '')
.find(h => /\\/member\\/\\d+/.test(h));
const uidMatch = String(profileLink || '').match(/\\/member\\/(\\d+)/);
return { user_id: uidMatch?.[1] || '', nickname };
})()
`);View on GitHub (pinned to 49907e53dc)
Solutions
- Run the dianping login flow (loginUrl https://account.dianping.com/pclogin) and complete it interactively to obtain the dper cookie.
- Persist cookies between runs (save/restore browser storage state) so a prior login is reused.
- Verify cookies are set for the www.dianping.com domain, not a sibling domain, and that the dper value is non-empty.
- If dper exists but auth still fails, log in again — the cookie may be expired server-side.
Example fix
// before
await cli.dianping.search({ keyword: '火锅' });
// after
if (!ctx.cookies.some(c => c.name === 'dper' && c.value)) {
await cli.dianping.login(); // completes account.dianping.com/pclogin
}
await cli.dianping.search({ keyword: '火锅' }); Defensive patterns
Strategy: validation
Validate before calling
const cookies = await page.getCookies({ url: 'https://www.dianping.com' });
if (!cookies.some(c => c.name === 'dper' && c.value)) await runDianpingLogin(page); Type guard
function hasDper(cookies) { return Array.isArray(cookies) && cookies.some(c => c.name === 'dper' && !!c.value); } Try / catch
try { await cli.dianping.verify(); }
catch (e) { if (e.name === 'AuthRequiredError') { await cli.dianping.login(); return cli.dianping.verify(); } throw e; } Prevention
- Persist and reload browser storage state between runs so cookies survive.
- Always log in on account.dianping.com/pclogin before data commands.
- Check cookie domain is www.dianping.com and dper value is non-empty.
- Re-login proactively when sessions are old.
When it happens
Trigger: Calling any dianping command (search, verify, etc.) in a browser page where the user never logged in, or after cookies were cleared/expired so `page.getCookies({url:'https://www.dianping.com'})` contains no non-empty `dper` entry.
Common situations: Fresh automation profile with no saved cookies; cookies wiped between runs; logged into the wrong Dianping-related domain (m.dianping.com vs www.dianping.com); headless login flow failed silently.
Related errors
- 1point3acres Discuz *_auth cookie missing
- Douban dbcl2 / ck cookies missing
- hupu.com
- jd.com
- jianyu360.cn
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/cb8fb2d91890eea5.
Report an issue: GitHub.