jackwener/OpenCLI · error · Error
User not found: ' + username (or 'HTTP ' + r1.status + ' - m
Error message
User not found: ' + username (or 'HTTP ' + r1.status + ' - make sure you are logged in to Instagram')
What it means
The feed-by-username pre-fetch fails the res.ok check: a 404 is mapped to 'User not found: <username>' while any other non-ok status yields 'HTTP <status> - make sure you are logged in to Instagram'. The comment flow aborts before locating the post.
Source
Thrown at clis/instagram/comment.js:54
if (!feed || typeof feed !== 'object' || !Array.isArray(feed.items)) {
throw new Error(label + ' returned malformed items payload');
}
if (idx >= feed.items.length) throw new Error('Post index ' + (idx + 1) + ' not found');
const post = feed.items[idx];
const pkRaw = post?.pk ?? post?.id;
const pk = typeof pkRaw === 'number' ? String(pkRaw) : (typeof pkRaw === 'string' ? pkRaw.trim() : '');
if (!/^\\d+$/.test(pk)) throw new Error(label + ' returned malformed post row');
return { pk };
}
function assertOkStatus(payload, label) {
if (!payload || typeof payload !== 'object' || payload.status !== 'ok') {
throw new Error(label + ' returned no success evidence');
}
}
// web_profile_info answers HTTP 400 for business accounts; feed-by-username needs no user id. See #2234.
const r1 = await fetch('https://www.instagram.com/api/v1/feed/user/' + encodeURIComponent(username) + '/username/?count=' + (idx + 1), opts);
if (!r1.ok) throw new Error(r1.status === 404 ? 'User not found: ' + username : 'HTTP ' + r1.status + ' - make sure you are logged in to Instagram');
const { pk } = getPostFromFeed(await readInstagramJson(r1, 'Instagram feed-by-username'), 'Instagram feed-by-username');
const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';
const r2 = await fetch('https://www.instagram.com/api/v1/web/comments/' + pk + '/add/', {
method: 'POST', credentials: 'include',
headers: { ...headers, 'X-CSRFToken': csrf, 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'comment_text=' + encodeURIComponent(commentText),
});
if (!r2.ok) throw new Error('Failed to comment: HTTP ' + r2.status);
assertOkStatus(await readInstagramJson(r2, 'Instagram comment'), 'Instagram comment');
return [{ status: 'Commented', user: username, text: commentText }];
})()
` },
],
});
View on GitHub (pinned to 49907e53dc)
Solutions
- Verify the username is correct and the account exists/public
- Refresh Instagram login cookies before running; the 'not logged in' branch almost always means stale cookies
- Add backoff/retry on 429 and reduce request frequency
- Handle 404 as a terminal skip in automation instead of retrying
Example fix
// before
if (!r1.ok) throw new Error(r1.status === 404 ? 'User not found: ' + username : 'HTTP ' + r1.status + ' - make sure you are logged in to Instagram');
// after
if (!r1.ok) {
if (r1.status === 404) throw new Error('User not found: ' + username);
if (r1.status === 429) throw new Error('Rate limited by Instagram - wait and retry');
throw new Error('HTTP ' + r1.status + ' - make sure you are logged in to Instagram');
} Defensive patterns
Strategy: validation
Validate before calling
if (!username || typeof username !== 'string' || /[^A-Za-z0-9._]/.test(username)) {
throw new Error('Invalid username: ' + username);
}
// ensure cookies are loaded before running
if (!cookies.includes('sessionid')) throw new Error('Not logged in - missing session cookie'); Type guard
function isValidUsername(u) {
return typeof u === 'string' && /^[A-Za-z0-9._]{1,30}$/.test(u);
} Try / catch
try {
await runCommentPipeline(args);
} catch (e) {
if (/User not found/.test(e.message)) {
console.warn('Skip: account does not exist');
} else if (/HTTP \d+/.test(e.message)) {
console.error('Refresh Instagram login cookies and retry');
} else throw e;
} Prevention
- Validate usernames before invoking
- Keep sessionid/csrftoken cookies fresh
- Throttle requests to avoid 429s
- Handle 404 as terminal skip in bulk jobs
When it happens
Trigger: Username does not exist (404); session cookies expired or missing so Instagram returns 302/401/403; rate limiting (429); the count parameter request rejected by IG.
Common situations: Typo in --username or the account was renamed/deleted; cookies stale after password change or logout elsewhere; running many requests in a row triggering IG throttling; business accounts where older endpoints 400 (the CLI already switched to feed-by-username, see #2234).
Related errors
- Instagram returned non-ok status: ${JSON.stringify(d).slice(
- Failed to comment: HTTP ' + r2.status
- Failed to fetch followers: HTTP ' + r2.status
- Failed to fetch following: HTTP ' + r2.status
- Instagram login required before posting
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4a7f88e761c8d767.
Report an issue: GitHub.