jackwener/OpenCLI · critical · AuthRequiredError
www.youtube.com
Error message
www.youtube.com
What it means
AuthRequiredError re-thrown after the in-page unsubscribe API call reports error === 'auth'. A SAPISID cookie existed, but YouTube's subscribe/unsubscribe internal endpoint responded as unauthenticated (e.g. HTTP 401), so the library surfaces AuthRequiredError for www.youtube.com. This indicates the stored session is no longer server-side valid.
Source
Thrown at clis/youtube/unsubscribe.js:69
'Content-Type': 'application/json',
'Authorization': authHash,
'X-Origin': 'https://www.youtube.com',
},
body: JSON.stringify({ context, channelIds: [channelId] }),
});
if (resp.status === 401 || resp.status === 403) return { error: 'auth', message: 'Not logged in' };
if (!resp.ok) {
const body = await resp.json().catch(() => ({}));
const errStatus = body?.error?.status || '';
if (errStatus === 'UNAUTHENTICATED') return { error: 'auth', message: 'Not logged in' };
return { error: 'http', message: 'HTTP ' + resp.status + (errStatus ? ' ' + errStatus : '') };
}
return { ok: true, channelId };
})()
`);
if (result?.error === 'auth') {
throw new AuthRequiredError('www.youtube.com');
}
if (result?.error) {
throw new CommandExecutionError(result.message || 'Failed to unsubscribe');
}
return [{ status: 'success', message: 'Unsubscribed from: ' + (result.channelId || channelInput) }];
},
});
View on GitHub (pinned to 49907e53dc)
Solutions
- Re-login to www.youtube.com in the automation profile to mint fresh session cookies, then retry.
- Delete stale YouTube cookies and sign in again so SAPISID matches a live session.
- Confirm the page-side request sends a correct SAPISIDHASH Authorization header with the current origin and SAPISID.
- Update the library/tooling if YouTube altered its internal unsubscribe endpoint auth behavior.
Defensive patterns
Strategy: try-catch
Validate before calling
const sapisid = await readYoutubeSapisid(page);
if (!sapisid) throw new Error('YouTube session invalid — re-login required'); Try / catch
try {
await unsubscribe({ channel });
} catch (e) {
if (e.name === 'AuthRequiredError') {
await refreshYoutubeSession(page);
return unsubscribe({ channel });
}
throw e;
} Prevention
- Re-login when internal API calls return 401 even with a SAPISID present — the session is server-side stale.
- Periodically validate the session with a lightweight authenticated API call before batch operations.
- Keep Authorization (SAPISIDHASH) header generation current with ytcfg and origin.
- Handle account security/consent walls that can invalidate subscriptions API access.
When it happens
Trigger: The page.evaluate payload returns { error: 'auth' } — the /youtubei/v1/subscription/unsubscribe call returns 401 or another auth-required status despite the SAPISID cookie being present.
Common situations: Expired/stale SAPISID from a revoked Google session; account security changes invalidating cookies; consent or verification walls on the account; YouTube changing auth expectations for internal APIs.
Related errors
- www.youtube.com
- 请先在共享 Chrome 完成 1688 登录/验证,再重试(${action})
- Bilibili ${label} API requires login or permission: ${messag
- bilibili.com
- ${probe.detail}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/36608926840a4512.
Report an issue: GitHub.