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
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With