pytube: [BUG] urllib.error.HTTPError: HTTP Error 404: Not Found

Describe the bug urllib.error.HTTPError: HTTP Error 404: Not Found cannot download video or list out streams (sometimes the download did work but most of the time it throws the same error)

To Reproduce Using Command CLI: pytube https://www.youtube.com/watch?v=1MmQUT3TjtI --list

Expected behavior A list of streams is printed

Output

Traceback (most recent call last):
  File "c:\program files\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\program files\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Program Files\Python39\Scripts\pytube.exe\__main__.py", line 7, in <module>
  File "c:\program files\python39\lib\site-packages\pytube\cli.py", line 50, in main
    _perform_args_on_youtube(youtube, args)
  File "c:\program files\python39\lib\site-packages\pytube\cli.py", line 63, in _perform_args_on_youtube
    display_streams(youtube)
  File "c:\program files\python39\lib\site-packages\pytube\cli.py", line 489, in display_streams
    for stream in youtube.streams:
  File "c:\program files\python39\lib\site-packages\pytube\__main__.py", line 310, in streams
    return StreamQuery(self.fmt_streams)
  File "c:\program files\python39\lib\site-packages\pytube\__main__.py", line 213, in fmt_streams
    if "adaptive_fmts" in self.player_config_args:
  File "c:\program files\python39\lib\site-packages\pytube\__main__.py", line 187, in player_config_args
    self._player_config_args = self.vid_info
  File "c:\program files\python39\lib\site-packages\pytube\__main__.py", line 280, in vid_info
    return dict(parse_qsl(self.vid_info_raw))
  File "c:\program files\python39\lib\site-packages\pytube\__main__.py", line 108, in vid_info_raw
    self._vid_info_raw = request.get(self.vid_info_url)
  File "c:\program files\python39\lib\site-packages\pytube\request.py", line 52, in get
    response = _execute_request(url, headers=extra_headers, timeout=timeout)
  File "c:\program files\python39\lib\site-packages\pytube\request.py", line 36, in _execute_request
    return urlopen(request, timeout=timeout)  # nosec
  File "c:\program files\python39\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "c:\program files\python39\lib\urllib\request.py", line 523, in open
    response = meth(req, response)
  File "c:\program files\python39\lib\urllib\request.py", line 632, in http_response
    response = self.parent.error(
  File "c:\program files\python39\lib\urllib\request.py", line 561, in error
    return self._call_chain(*args)
  File "c:\program files\python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "c:\program files\python39\lib\urllib\request.py", line 641, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found

System information

  • Python version 3.9.5
  • Pytube version 10.8.4
  • Command used to install pytube: pip install git+https://github.com/pytube/pytube

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 12
  • Comments: 41

Commits related to this issue

Most upvoted comments

If you’re here and would like to help me validate the fix that I’m making, you can test this branch.

I already know that this branch does not work for age-restricted videos. If you can find other videos that it does not work for, please let me know.

The error that I see when I use it for an age-restricted video is as follows:

Traceback (most recent call last):
  File ".\test.py", line 103, in <module>
    print(yt.streams)
  File "C:\Users\Taylor Fox\AppData\Local\Programs\Python\Python38\lib\site-packages\pytube\__main__.py", line 327, in streams
    return StreamQuery(self.fmt_streams)
  File "C:\Users\Taylor Fox\AppData\Local\Programs\Python\Python38\lib\site-packages\pytube\__main__.py", line 236, in fmt_streams
    extract.apply_descrambler(self.player_config_args, fmt)
  File "C:\Users\Taylor Fox\AppData\Local\Programs\Python\Python38\lib\site-packages\pytube\extract.py", line 500, in apply_descrambler
    streaming_data = stream_data["player_response"]["streamingData"]
KeyError: 'streamingData'

I’m going to continue working on trying to find a way around that, and I also need to update a lot of unit tests to reflect the changes that this makes.

I found this answer on Stackoverflow and could serve as a temporary solution. Here is the link: https://stackoverflow.com/a/67629882

It seems like adding &c=TVHTML5&cver=7.20201028 to get_video_info fixes the problem.

I believe the reason why it still works is that Smart-TVs still use this method to some degree, hence the c=TVHTML5.

So changing the code in pytube/extract.py from:

def _video_info_url(params: OrderedDict) -> str:
    return "https://www.youtube.com/get_video_info?" + urlencode(params)

to:

def _video_info_url(params: OrderedDict) -> str:
    return "https://www.youtube.com/get_video_info?" + urlencode(params) + "&c=TVHTML5&cver=7.20201028"

Also there are different versions of cver which seems to add extra information to get_video_info. Here are some of the versions: 5.20150304, 6.20180913, 7.20200909, 7.20201028, 7.20201122, 7.20201208, 7.20210106, 7.20210228, 7.20210330, 7.20210406, 7.20210414, 7.20210519 and 7.20211231. I don’t know if these versions add some extra metadata or not, but I can confirm that 5.20150304 and 6.20180913 gives the least amount of data.

I’m merging a fix for this once it passes tests. Ty @AllanVester for finding that workaround. Expect a new release on pypi within the next 10 minutes hopefully

I’m having the same problem, has anyone found a solution??

@itayseer I don’t believe those changes will work for accessing age-restricted videos without authentication. I currently have a working solution for videos that are not age-restricted which I will merge shortly, but it does break age-restricted videos.

@friendlyvisuals @clo0wn @KDKftw – the 404 error you’re seeing is a new problem. See #1060 for updates.

same issue happening for me as welll http 404 not found https://www.youtube.com/watch?v=G5RpJwCJDqc

Please help guys!!!

I have the same error, until about 4 hours ago it was working fine. Yesterday I had this problem but it was intermittent.

Today I had this same error, yesterday was working fine

Looks like we aren’t the only ones running into this issue, it looks like the get_video_info API might be getting shut down. I have an incomplete solution for videos that aren’t age-restricted, but I don’t know of a way to fix this for age-restricted videos.

still happens to me unfortunately even with the updated version 10.9.3. In my case I dont really see difference between age-restricted video or non-restricted.

Same problem, pytube version 10.9.3

fwiw I’m still running into this issue after update.

New version should be released on pypi; please update to v10.8.5 with python -m pip install --upgrade pytube.

@tfdahlin This error happens from time to time. I’m having a lot of issues rising for 3 days now saying Error 404: Not found. I hope you can come up with a solution that solves this issue permanently 👍

I found this answer on Stackoverflow and could serve as a temporary solution. Here is the link: https://stackoverflow.com/a/67629882 It seems like adding &c=TVHTML5&cver=7.20201028 to get_video_info fixes the problem. I believe the reason why it still works is that Smart-TVs still use this method to some degree, hence the c=TVHTML5. So changing the code in pytube/extract.py from:

def _video_info_url(params: OrderedDict) -> str:
    return "https://www.youtube.com/get_video_info?" + urlencode(params)

to:

def _video_info_url(params: OrderedDict) -> str:
    return "https://www.youtube.com/get_video_info?" + urlencode(params) + "&c=TVHTML5&cver=7.20201028"

Also there are different versions of cver which seems to add extra information to get_video_info. Here are some of the versions: 6.20180913, 7.20201028 and 7.20210228. I don’t know if these versions add some extra metadata or not, but I can confirm that 6.20180913 gives the least amount of data.

it work for me now

Yes you are right. I tried it here and it works. https://github.com/snakx/YouTubeApiSharp/commit/e7dd7720f34e7f454d44a625f5fe39c5535ec9fb

I found this answer on Stackoverflow and could serve as a temporary solution. Here is the link: https://stackoverflow.com/a/67629882

It seems like adding &c=TVHTML5&cver=7.20201028 to get_video_info fixes the problem.

I believe the reason why it still works is that Smart-TVs still use this method to some degree, hence the c=TVHTML5.

So changing the code in pytube/extract.py from:

def _video_info_url(params: OrderedDict) -> str:
    return "https://www.youtube.com/get_video_info?" + urlencode(params)

to:

def _video_info_url(params: OrderedDict) -> str:
    return "https://www.youtube.com/get_video_info?" + urlencode(params) + "&c=TVHTML5&cver=7.20201028"

Also there are different versions of cver which seems to add extra information to get_video_info. Here are some of the versions: 6.20180913, 7.20201028 and 7.20210228. I don’t know if these versions add some extra metadata or not, but I can confirm that 6.20180913 gives the least amount of data.

it work for me now

Hi, guys

The network layer is totally fine. i am checking the source code. Seems something has been changed by google/youtube yesterday. and we have to find it out, and fix the problems.

I tried some other methods, to download the videos. like ‘you-get’, but same thing happened to me. the first time is OK, however, when i tried it again, error occurred, just like ‘pytube’

Youtube take money from the AD, if we watch the videos without watching their ADs, sooner or later, google will stop us.

Looks like ytdl tackled with a fallback if they hit this message (not great in Python, so could be off) but they closed two bugs on this 18 days ago. See: https://github.com/ytdl-org/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L1475