The fix everyone gives for yt-dlp's "Sign in to confirm you're not a bot" is to pass your YouTube cookies. It works. Then a day or two later the same error is back, with the same cookies.txt, and nothing in your command changed.
I hit this enough times that it's worth writing down why it happens and what keeps the cookies alive longer.
YouTube rotates the session you exported from
If you export cookies from a browser window you keep using, YouTube keeps refreshing that session while the tab is open. Your exported file still holds the old values, so after a while it's a stale copy of a session that has moved on. The yt-dlp wiki says it directly: YouTube rotates account cookies frequently on open YouTube tabs as a security measure.
So the export has to come from a session nothing else will touch again:
- Open a private or incognito window and sign in to YouTube.
- In that same tab, go to
https://www.youtube.com/robots.txt. Keep it the only private tab open. - Export the youtube.com cookies to
cookies.txtwith a cookies.txt browser extension. - Close the private window. Don't sign out first, since that kills the session you just exported.
Use a separate Google account for this, not your personal one. Automated traffic can get an account challenged, and you don't want that to be the account you use every day.
Let yt-dlp write the refreshed cookies back
--cookies FILE doesn't only read the file. yt-dlp also dumps its cookie jar back into it when it exits, so the file picks up whatever the site set during the run. You can see it with any site:
printf '# Netscape HTTP Cookie File\n' > cookies.txt
yt-dlp --cookies cookies.txt --skip-download "URL"
head -3 cookies.txt
# # Netscape HTTP Cookie File
# # This file is generated by yt-dlp. Do not edit.
That matters in Docker and CI. If you mount the file read-only, or copy a fresh one from a secret on every run, you throw those updates away each time. Mount it somewhere writable and keep it between runs:
docker run --rm -v "$PWD/cookies.txt:/cookies.txt" -v "$PWD:/downloads" \
your-yt-dlp-image --cookies /cookies.txt "URL"
--cookies-from-browser isn't the same thing
--cookies-from-browser firefox reads your normal browser profile, so it's handy on a laptop. It won't pick up the private-window session from above, and on Windows recent Chrome builds encrypt cookies so yt-dlp reports Failed to decrypt with DPAPI. On a server there's no browser anyway, so the exported file is the way.
When fresh cookies still fail
If a cookies file exported the careful way fails right away on a server but works from your laptop, the cookies aren't the problem. YouTube is reacting to the server's IP, and datacenter and CI ranges get challenged far harder than home connections. Slowing down (--sleep-requests 1, or the -t sleep preset) helps when bursts trigger the check, not when the IP itself is distrusted.
I wrote up the full checklist, including PO tokens and player clients, here: https://ytdlp.org/guides/fix-sign-in-to-confirm-not-a-bot
For a personal script, a careful export plus a writable cookies file usually gets you weeks instead of a day. If this runs inside an app you ship, plan for the cookies to expire and the IP to get challenged anyway. That's why I built Importly (https://www.importly.io/?utm_source=devto&utm_medium=article&utm_campaign=syndication&utm_content=ytdlp-cookies-stale) - you send it a link from your backend and get the file, transcript or metadata back, without keeping a YouTube account's cookies alive on your server.
Top comments (0)