Fix "Permission denied" Reading Browser Cookies in yt-dlp
ERROR: unable to open cookie file: PermissionError(13, 'Permission denied')
# or, on Linux with a Chromium browser:
ERROR: Failed to decrypt with DPAPI. See https://github.com/yt-dlp/yt-dlp/issues/7271
Quick answer
The cookie file exists and yt-dlp cannot read it — a different problem on each OS. On Linux it is the desktop keyring holding the decryption key; on macOS, Keychain; on Windows, a file lock. The one route that works everywhere is to stop reading the browser and export instead:
yt-dlp --cookies cookies.txt "URL"
Linux: the keyring
Chromium browsers on Linux encrypt cookie values with a key kept in the desktop keyring — GNOME Keyring or KWallet. yt-dlp can read the database, gets ciphertext, and has to ask the keyring to decrypt it. That request fails when the keyring is locked, when there is no desktop session, or when D-Bus is not reachable.
Tell yt-dlp which keyring to use:
yt-dlp --cookies-from-browser "chromium+gnomekeyring" "URL"
yt-dlp --cookies-from-browser "chromium+kwallet" "URL"
Under SSH with no session bus, the keyring is simply not there. Either export to a file, or use Firefox — its cookie file is not keyring-encrypted, which makes it the reliable choice on headless machines:
yt-dlp --cookies-from-browser firefox "URL"
macOS: Keychain
Safari and Chrome both keep their key in Keychain, and macOS prompts for permission the first time yt-dlp asks. If the prompt was dismissed, the denial is remembered and yt-dlp fails silently from then on.
Open Keychain Access, search for Chrome Safe Storage, and check
its Access Control tab — the denial is recorded there and can be removed. Then retry.
Safari needs Full Disk Access granted to your terminal, under System Settings → Privacy & Security. It is a broad permission to hand a terminal; Firefox avoids the question entirely.
Windows: locks and DPAPI
On Windows, "permission denied" is usually a lock rather than a permission. Close the browser properly — including background processes — and retry. If the error mentions DPAPI, the browser is Chrome 127 or newer and the encryption is bound to the browser process; no amount of permission fixes that. The Chrome cookie database page covers that case in full.
The approach that always works
Export once, in the browser, where the key is available. Install a cookies.txt exporter extension, export while signed in to the site, and pass the file:
yt-dlp --cookies ~/cookies.txt "URL"
Then set permissions so the file is not readable by other accounts on the machine:
chmod 600 ~/cookies.txt
Confirming it worked
yt-dlp --cookies cookies.txt --simulate -v "URL"
Verbose output reports the cookie count. Zero from a file means the export produced a header and nothing else — a common outcome when the export was done from a page other than the site you need cookies for.
If it still fails
- "does not look like a Netscape format cookies file". The exporter produced JSON. Use one that offers Netscape format explicitly — yt-dlp reads only that.
- Cookies load, access still refused. The session is valid and lacks permission, or the account is not the one with access. See private video.
- Worked, then stopped after a few days. Exported cookies expire. Sessions are rotated, and YouTube rotates them faster for accounts it considers unusual. Re-export.
- Inside Docker. There is no browser and no keyring in the container. Mount a cookies.txt read-only — the Docker guide shows the volume.
Frequently asked
Why does yt-dlp need my keyring?
It works in my terminal but not from cron.
Can I run yt-dlp with sudo to get past this?
Is a cookies.txt file less secure than reading the browser directly?
Related
- Fix "Could not copy Chrome cookie database" in yt-dlp Chrome locks its cookie file while it is running, and on newer versions encrypts it so only Chrome can read it...
- yt-dlp Cookies: --cookies-from-browser vs cookies.txt Cookies are how yt-dlp proves it is you — for private videos, members-only content and bot checks. Both method...
- Install yt-dlp on Linux Without Your Distro's Stale Package Almost every distro ships a yt-dlp too old to download from YouTube. Why that happens, how to install a build...