Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: unable to download video data: HTTP Error 403: Forbidden while using youtube_dl

I am trying to download songs from youtube using python 3.8 and youtube_dl 2020.3.24. But the weird thing is that most songs I try to download don't get downloaded. I'm talking 99% of them. The ones that do get downloaded get the following Error from youtube_dl:

ERROR: unable to download video data: HTTP Error 403: Forbidden

It is worth saying that this happened overnight and I did not change any code. before this everything worked fine. I have friends who ran the same code and they did not get this Error

like image 519
Lukas Avatar asked Apr 16 '20 11:04

Lukas


People also ask

What causes HTTP 403 forbidden error?

The 403 Forbidden error appears when your server denies you permission to access a page on your site. This is mainly caused by a faulty security plugin, a corrupt . htaccess file, or incorrect file permissions on your server.

How do I fix error 403 forbidden in any website in Google Chrome?

Reset everything: If the 403 forbidden error on Google Chrome only happens on a specific internet connection, turn off your router or modem, wait a few seconds and then turn things back on again. Hopefully by rebooting your connection the issue will solve itself.


2 Answers

Same problem many times .. solution: youtube-dl --rm-cache-dir

Cause of the problem: Sometimes I download playlists of large videos and I force it to stop downloading, the next time I run the command to resume the download, the 403 problem arises

At the moment, the cache directory is used only to store youtube players for obfuscated signatures. Since all videos in playlist use simple signatures

Playlist caching is an obvious way to detect changed titles or changed playlists in general

like image 149
Alexander Willam Vera Paco Avatar answered Sep 19 '22 17:09

Alexander Willam Vera Paco


It seems like i have figured it out on my own. The Error went away after i cleared the cache.

            with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            try:
                ydl.cache.remove()
                ydl.download([youtube_link])
            except youtube_dl.DownloadError as error:
                pass

Any info on why this works is welcome

like image 31
Lukas Avatar answered Sep 18 '22 17:09

Lukas