jackwener/OpenCLI · error · AuthRequiredError
nowcoder.com
Error message
nowcoder.com
What it means
fetchNowcoderData navigates a browser page to nowcoder.com and calls the JSON API. If the underlying fetch fails with an HTTP 401/403 status or an error message indicating 'need login' / 'not logged in', the library rethrows it as AuthRequiredError with host 'nowcoder.com', signaling that a valid logged-in Nowcoder session (cookies) is required. The message field of the error is the host string 'nowcoder.com'.
Source
Thrown at clis/nowcoder/posts.js:247
};
}
export function requirePositiveInt(value, name, maximum) {
const number = Number(value);
if (!Number.isInteger(number) || number < 1 || number > maximum) throw new ArgumentError(`nowcoder --${name} must be an integer from 1 to ${maximum}`);
return number;
}
export async function fetchNowcoderData(page, url, options, label) {
let payload;
try {
await page.goto('https://www.nowcoder.com');
payload = await page.fetchJson(url, options);
}
catch (error) {
const detail = String(error?.message ?? error);
if (/HTTP\s+(401|403)|need login|not logged in/i.test(detail)) {
throw new AuthRequiredError('nowcoder.com', `${label} requires a logged-in Nowcoder session`);
}
throw new CommandExecutionError(`${label} failed: ${detail}`);
}
if (!isRecord(payload) || typeof payload.success !== 'boolean' || !Number.isSafeInteger(payload.code)) throw new CommandExecutionError(`${label} returned a malformed envelope`);
const message = typeof payload.msg === 'string' ? payload.msg : 'unknown error';
if (!payload.success || payload.code !== 0) {
if (payload.code === 999 || /need login|登录/i.test(message)) {
throw new AuthRequiredError('nowcoder.com', `${label} requires a logged-in Nowcoder session: ${message}`);
}
throw new CommandExecutionError(`${label} failed: ${message} (${payload.code})`);
}
if (!isRecord(payload.data)) throw new CommandExecutionError(`${label} returned malformed data`);
return payload.data;
}
View on GitHub (pinned to 49907e53dc)
Solutions
- Log in to https://www.nowcoder.com in the browser profile the CLI uses, then retry.
- Refresh/re-establish the session if your cookies expired.
- Verify the login by loading a members-only page in that profile.
- Avoid running from IPs that trigger auth challenges (datacenter IPs) or use a normal residential connection.
Example fix
// before // headless profile without session nowcoder posts list // AuthRequiredError: nowcoder.com // after // open the profile browser, log in at https://www.nowcoder.com, then rerun nowcoder posts list
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-flight: confirm an active session exists in the CLI's browser profile // e.g. open the profile, visit https://www.nowcoder.com, and confirm you are logged in before running commands
Try / catch
try {
const posts = await nowcoderPostsList(opts);
} catch (err) {
if (err instanceof AuthRequiredError && err.message === 'nowcoder.com') {
console.error('Log in to www.nowcoder.com in the CLI browser profile, then retry.');
process.exitCode = 3;
} else throw err;
} Prevention
- Log in to nowcoder.com in the browser profile the CLI drives before running data commands.
- Re-login periodically; Nowcoder sessions expire.
- Don't run from datacenter IPs that trigger auth challenges.
- Verify login state with a quick members-only page check before batch jobs.
When it happens
Trigger: Calling a nowcoder data command while the browser profile has no valid session cookies; session expired; Nowcoder's API returns 401/403 or a 'need login' / 'not logged in' failure for the endpoint.
Common situations: Running the CLI in CI or a headless environment without first logging in; cookies expiring after a few days; IP flagged by Nowcoder triggering auth challenges; using a fresh browser profile that never logged in.
Related errors
- ${label} returned HTTP ${resp.status}: ${summarizeApiError(p
- Bilibili creator-center login is required: ${message}
- Bilibili creator-center login is required: ${detail}
- Boss redirected to login page
- ${reason}${detail}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/2571288bf7925af4.
Report an issue: GitHub.