Youtube-dl is my favorite and preferred command line download manager. I often use it to download audios, videos and movies from Internet. Today, I tried to download a video from YouTube using youdtube-dl from my Linux desktop and got this error message – Unable to download video data: HTTP Error 403: Forbidden. Usually, most youtube-dl errors will be fixed after updating youtube-dl. So I updated youtube-dl using command:

				
					$ sudo youtube-dl -U
				
			

It is already updated! I have the most recent version.

And then I tried again to download the video with command:

				
					$ youtube-dl https://www.youtube.com/watch?v=NacpCNEs1QE
				
			

But I get the same error:

				
					[youtube] NacpCNEs1QE: Downloading webpage
WARNING: Requested formats are incompatible for merge and will be merged into mkv.
ERROR: unable to download video data: HTTP Error 403: Forbidden
				
			

If you ever encountered with this error, follow the steps given below to fix it.

How to Fix "Unable to download video data: HTTP Error 403: Forbidden" Error When Downloading Media Files With Youtube-dl In Linux

This error will probably happen because of Youtube-dl cache. To fix it, simply remove the cache for youtube-dl using command:

				
					$ youtube-dl --rm-cache-dir
				
			

This command command will remove the local caching directory for youtube-dl. In my case, it removed the following directory:

				
					Removing cache dir /home/hsn/.cache/youtube-dl ...
				
			

If you use Youtube-dl in Python code, the following will help to fix this error.

				
					# 'cachedir': False -> don't use a local caching dir (~/.cache/youtube-dl)
ydl_opts = {...,
            'cachedir': False
            }
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    result = ydl.extract_info(url)
				
			

Now, I was be able to download the youtube videos without any issues.

				
					$ youtube-dl https://www.youtube.com/watch?v=NacpCNEs1QE
				
			
				
					[youtube] NacpCNEs1QE: Downloading webpage
WARNING: Requested formats are incompatible for merge and will be merged into mkv.
[download] Destination: Reea feat. Akcent - Rain (Official Music Video)-NacpCNEs1QE.f137.mp4
[download] 100% of 55.57MiB in 00:06
[download] Destination: Reea feat. Akcent - Rain (Official Music Video)-NacpCNEs1QE.f251.webm
[download] 100% of 2.99MiB in 00:00
[ffmpeg] Merging formats into "Reea feat. Akcent - Rain (Official Music Video)-NacpCNEs1QE.mkv"
Deleting original file Reea feat. Akcent - Rain (Official Music Video)-NacpCNEs1QE.f137.mp4 (pass -k to keep)
Deleting original file Reea feat. Akcent - Rain (Official Music Video)-NacpCNEs1QE.f251.webm (pass -k to keep)
				
			

As you may probably noticed, there is a warning message in the above command:

				
					[...]
WARNING: Requested formats are incompatible for merge and will be merged into mkv.
[...]
				
			

This is not actually a problem but an expected behavior for youtube-dl command. By default, youtube-dl will download the highest quality audio and the highest quality video streams available and then join them into a compatible container like mkv, mp4 etc. If these audio and video streams doesn’t fit well in an mp4 container, youtube-dl will then pack them in mkv container and display the above warning message. In such cases, you can ignore the mkv warning and download the best quality video and the best quality audio but only in an mp4 container by explicitly mentioning the desired best quality audio and video formats like below:

				
					$ youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]' https://www.youtube.com/watch?v=NacpCNEs1QE
				
			

For more Youtube-dl command examples, refer the following guide.

Youtube-dl Tutorial With Examples For Beginners

Hope this helps.

About the author

Hassan Latif

A Microsoft Certified Trainer, a hobby blogger and geek

Leave a Comment