62

I have a problem with youtube-dl library (https://rg3.github.io/youtube-dl/). I use youtube-dl not for directly downloading videos by this library, instead I first generate link using command like this:

youtube-dl --simulate --dump-json --prefer-ffmpeg -- -CmadmM5cOk

I get needed format link from json answer, I use default format 1280x720 mp4. Links look like this "https://r4---sn-nto52nx-px8e.googlevideo.com/videoplayback?lmt=1432339993780507&ip=x.x.x.x&key=yt6&fexp=9408710%2C9409069%2C9413137%2C9415365%2C9415485%2C9416023%2C9416126%2C941...".

Then I use this link to download video from different PC in different locations. For most links it works ok, but there are some videos, for example https://www.youtube.com/watch?v=-CmadmM5cOk, that I can't download from different server or PC, it returns ERROR 403: Forbidden.

So what I tried so far, I have 2 server and my local PC, all 3 of them are located in different countries, USA, England and Ukraine.

For example, I run youtube-dl and get link on Server 1 in the USA, I get link, I can it download in this Sever 1, but on Server 2 in London and my local PC in Ukraine it returns ERROR 403: Forbidden.

Another example, I generate link on Server 2 in London, I get different link, I can download it on the same server, but when I try on Server 1 or my local PC I get the same ERROR 403: Forbidden. The same when I generate link on local PC and try on servers.

This happens only with only some exact videos, but there are a lot of them. Some of videos that returns 403: https://www.youtube.com/watch?v=09R8_2nJtjg, https://www.youtube.com/watch?v=7PCkvCPvDXk.

Thank you, I appreciate any help!

Update:

I'm trying to use suggested by you option "-o -" to output video file to stdout and then I retranslate it to user. But I have another problem, it works if I login with ssh and try command with my user, but it throws 403 error when I launch the same command under "www-data" user. Here is verbose output:

Here is verbose report:

[debug] System config: []
[debug] User config: []
[debug] Command-line args: [u'--prefer-ffmpeg', u'--no-warnings', u'-f', u'22', u'-o', u'-', u'-v', u'--', u'QcIy9NiNbmo']
[debug] Encodings: locale UTF-8, fs UTF-8, out UTF-8, pref UTF-8
[debug] youtube-dl version 2015.08.16.1
[debug] Python version 2.7.3 - Linux-4.1.0-x86_64-linode59-x86_64-with-debian-7.8
[debug] exe versions: avconv 0.8.17-6, avprobe 0.8.17-6, ffmpeg 0.8.17-6, ffprobe 0.8.17-6
[debug] Proxy map: {}
[youtube] QcIy9NiNbmo: Downloading webpage
[youtube] QcIy9NiNbmo: Downloading video info webpage
[youtube] QcIy9NiNbmo: Extracting video information
[youtube] {22} signature length 40.42, html5 player new
[youtube] {43} signature length 40.42, html5 player new
[youtube] {18} signature length 40.42, html5 player new
[youtube] {5} signature length 40.42, html5 player new
[youtube] {36} signature length 40.42, html5 player new
[youtube] {17} signature length 40.42, html5 player new
[youtube] {137} signature length 40.42, html5 player new
[youtube] {248} signature length 40.42, html5 player new
[youtube] {136} signature length 40.42, html5 player new
[youtube] {247} signature length 40.42, html5 player new
[youtube] {135} signature length 40.42, html5 player new
[youtube] {244} signature length 40.42, html5 player new
[youtube] {134} signature length 40.42, html5 player new
[youtube] {243} signature length 40.42, html5 player new
[youtube] {133} signature length 40.42, html5 player new
[youtube] {242} signature length 40.42, html5 player new
[youtube] {160} signature length 40.42, html5 player new
[youtube] {140} signature length 40.42, html5 player new
[youtube] {171} signature length 40.42, html5 player new
[youtube] QcIy9NiNbmo: Downloading DASH manifest
[debug] Invoking downloader on u'https://r6---sn-q4f7sn7s.googlevideo.com/videoplayback?dur=244.924&ipbits=0&sver=3&expire=1440076742&itag=22&lmt=1432153223392108&ratebypass=yes&fexp=9406010%2C9407118%2C9407156%2C9408710%2C9409069%2C9412515%2C9412774%2C9412779%2C9415365%2C9415485%2C9416023%2C9416126%2C9416326%2C9416916%2C9417707%2C9418153%2C9418449%2C9418954&key=yt5&mime=video%2Fmp4&initcwndbps=19078750&source=youtube&upn=H3j2i1TBZjA&mn=sn-q4f7sn7s&mm=31&pl=32&id=o-ADA7nHOi-VHvDpG35GbK7zvbnjmrppbPKN4PlVS25gcx&requiressl=yes&pcm2=no&ip=2600%3A3c00%3A%3Af03c%3A91ff%3Afe84%3A4cc7&mv=m&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpcm2%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&mt=1440055050&ms=au&signature=FCB04C87410298BCDA619B8DB06221417292500B.669E8F187A5885C08D057F924A9551A657FF584B'
ERROR: unable to download video data: HTTP Error 403: Forbidden
Traceback (most recent call last):
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 1585, in process_info
    success = dl(filename, info_dict)
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 1527, in dl
    return fd.download(name, info)
  File "/usr/local/bin/youtube-dl/youtube_dl/downloader/common.py", line 342, in download
    return self.real_download(filename, info_dict)
  File "/usr/local/bin/youtube-dl/youtube_dl/downloader/http.py", line 60, in real_download
    data = self.ydl.urlopen(request)
  File "/usr/local/bin/youtube-dl/youtube_dl/YoutubeDL.py", line 1860, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
  File "/usr/lib/python2.7/urllib2.py", line 407, in open
    response = meth(req, response)
  File "/usr/lib/python2.7/urllib2.py", line 520, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python2.7/urllib2.py", line 445, in error
    return self._call_chain(*args)
  File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 528, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden
Vedmant
  • 2,265
  • 1
  • 27
  • 36

9 Answers9

140

Final download URLs are only guaranteed to work on the same machine/IP where extracted. More on this.

UPD: To get rid of 403 remove the cache by running youtube-dl --rm-cache-dir on behalf of www-data.

dstftw
  • 2,941
  • 2
  • 16
  • 10
  • Thank you, I'm trying to implement downloading through server with -o - option, and I have another problem, it works normally under one user, but fails with 403 error under "www-data". I'm updating question. – Vedmant Aug 20 '15 at 07:21
  • what did you do to bypass this issue ? – AHmedRef Aug 20 '16 at 22:06
  • 4
    As explained in the answer and in [this issue](https://github.com/ytdl-org/youtube-dl/issues/24794) entering `youtube-dl --rm-cache-dir` at the command line fixes it. – Paul Rougieux Apr 28 '20 at 10:23
  • 2
    worked, but after 8 tracks I had the same error 403 again... – babipsylon Dec 29 '21 at 18:52
  • it seems like it's caused by the same track rather then by something on the local pc, rather some youtube triggered error – babipsylon Dec 29 '21 at 22:46
  • this happened to me right after fresh install (of macOS even). I'm now using this alias: `mp3='youtube-dl --rm-cache-dir && youtube-dl -x --audio-quality 0 --audio-format mp3 --no-playlist '` – Philipp Gächter Apr 21 '22 at 16:50
  • Not working in Ubuntu 22.04 – Matin Aug 15 '23 at 05:21
56
youtube-dl --rm-cache-dir

it works perfectly :)

Mickael B.
  • 4,755
  • 4
  • 24
  • 48
Paul
  • 561
  • 4
  • 2
10

I, too, was getting the 403 error. Tried clearing cache to no avail.

I added the "-v" switch to see if I could determine why the download was failing and, much to my surprise, the video started downloading.

Go figure. YMMV.

whatshisname
  • 131
  • 1
  • 6
2

For me it worked to use yt-dlp --update once.

Falk
  • 21
  • 2
  • Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? **If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient.** Can you kindly [edit] your answer to offer an explanation? – Jeremy Caney Aug 27 '23 at 10:14
  • I also had to use this same switch for it to work for me. I was using a version from February of 2023 and it upgraded me to a version from July of 2023. – ddelrio1986 Aug 28 '23 at 17:14
1

If dstftw's answer doesn't work for you, try with root: su youtube-dl --rm-cache-dir

mittmemo
  • 2,062
  • 3
  • 20
  • 27
John
  • 19
  • 1
  • 5
    If this worked for you, but the same command without `su` did not, then it means your user profile permissions are broken. Likely you ran `youtube-dl` as root - there is never a good reason to do this. I recommend you change your cache dir permissions (`/home//.cache/youtube-dl` on Ubuntu) to the permissions of your actual user, recursively. – aggregate1166877 Sep 13 '21 at 08:04
1

If non of the options above works then simply do:

pip install yt-dlp --upgrade

:)

0

I tried clearing cache, continued to get 403. Had to add cookies (--cookies cookies.txt). This still required me to occasionally restart.

Ryanman
  • 880
  • 1
  • 8
  • 20
0

The accepted answer works perfectly.

If anybody is using yt-dlp instead of youtube-dl, then use yt-dlp --rm-cache-dir and it also works.

Anish B.
  • 9,111
  • 3
  • 21
  • 41
0

Try to upgrade to the latest version of yt-dlp.

python -m pip install -U yt-dlp
toyota Supra
  • 3,181
  • 4
  • 15
  • 19