Home Command line utilities Fix “Unable to download video data: HTTP Error 403: Forbidden” Error

Fix “Unable to download video data: HTTP Error 403: Forbidden” Error

By sk
26.5K views

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=4jTy5jnMkYc

But I get the same error:

[youtube] 4jTy5jnMkYc: 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.

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/sk/.cache/youtube-dl ...

Fix "Unable to download video data: HTTP Error 403: Forbidden" Error

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 can be able to download the youtube videos without any issues.

$ youtube-dl https://www.youtube.com/watch?v=4jTy5jnMkYc
[youtube] 4jTy5jnMkYc: Downloading webpage
[youtube] 4jTy5jnMkYc: Downloading js player vflset
[youtube] 4jTy5jnMkYc: Downloading js player vflset
WARNING: Requested formats are incompatible for merge and will be merged into mkv.
[download] Destination: Takkar _ Nira Song Lyric Video _ Siddharth _ Sid Sriram _ Gautham Menon _ Nivas K Prasanna-4jTy5jnMkYc.f137.mp4
[download] 100% of 29.87MiB in 00:24
[download] Destination: Takkar _ Nira Song Lyric Video _ Siddharth _ Sid Sriram _ Gautham Menon _ Nivas K Prasanna-4jTy5jnMkYc.f251.webm
[download] 100% of 5.10MiB in 00:04
[ffmpeg] Merging formats into "Takkar _ Nira Song Lyric Video _ Siddharth _ Sid Sriram _ Gautham Menon _ Nivas K Prasanna-4jTy5jnMkYc.mkv"
Deleting original file Takkar _ Nira Song Lyric Video _ Siddharth _ Sid Sriram _ Gautham Menon _ Nivas K Prasanna-4jTy5jnMkYc.f137.mp4 (pass -k to keep)
Deleting original file Takkar _ Nira Song Lyric Video _ Siddharth _ Sid Sriram _ Gautham Menon _ Nivas K Prasanna-4jTy5jnMkYc.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=4jTy5jnMkYc

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

Hope this helps.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

10 comments

perplexed April 27, 2020 - 11:27 pm

That’ll be real useful if you included where to make this change.

Reply
joncjg April 28, 2020 - 3:42 pm

Well done. Thank you.

Reply
Delivator April 29, 2020 - 7:21 pm

YES! Thanks!

Reply
01101001b May 1, 2020 - 4:57 am

Brilliant! Thx! =)

Reply
ilias_s May 1, 2020 - 7:23 am

thank you! that helped me, after a PC crash the cache got corrupted i guess

Reply
Madhur May 1, 2020 - 6:04 pm

The tutorial worked for me to sort out the error.

Reply
Fat Mata May 1, 2020 - 9:03 pm

Thanks a lot for correlating error and fix and the step by step explanation. This worked for me on android.

Reply
sk May 1, 2020 - 10:11 pm

Happy to help. How do you use youtube-dl on Android? Is there a youtube-dl client for Android?

Reply
Mohamed Benchohra June 3, 2020 - 4:56 am

Didn’t work for me, requesting the webm format worked though. Turns out the problem is fetching the mp4 format.

-f “webm[height=720]” instead of -f “best[height<=720]"

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More