pytube: HTTP Error 404: Not Found when trying get stream

Describe the bug I need to get URL to upload the video on AWS. The code is simplest as possible

yt = YouTube(video_url)
streams = yt.streams

The video that I want to download: http://youtube.com/watch?v=2lAe1cqCOXo On the line where we get streams, it returns the error urllib.error.HTTPError: HTTP Error 404: Not Found It’s happening not always around once at 2-3 requests.

Full error list:

Internal Server Error: /api/external-video-upload/
Traceback (most recent call last):
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/core/handlers/base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/sentry_sdk/integrations/django/views.py", line 67, in sentry_wrapped_callback
    return callback(request, *args, **kwargs)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/alex/Developer/blossom-backend/blossom/recordings/views.py", line 819, in get
    youtube_video_upload(video_url, recording)
  File "/home/alex/Developer/blossom-backend/blossom/recordings/utils.py", line 791, in youtube_video_upload
    streams = yt.streams
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 321, in streams
    return StreamQuery(self.fmt_streams)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 214, in fmt_streams
    if "adaptive_fmts" in self.player_config_args:
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 188, in player_config_args
    self._player_config_args = self.vid_info
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 291, in vid_info
    return dict(parse_qsl(self.vid_info_raw))
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 109, in vid_info_raw
    self._vid_info_raw = request.get(self.vid_info_url)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/request.py", line 53, in get
    response = _execute_request(url, headers=extra_headers, timeout=timeout)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/request.py", line 37, in _execute_request
    return urlopen(request, timeout=timeout)  # nosec
  File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 523, in open
    response = meth(req, response)
  File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 632, in http_response
    response = self.parent.error(
  File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 561, in error
    return self._call_chain(*args)
  File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/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
Internal Server Error: /api/external-video-upload/
Traceback (most recent call last):
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/core/handlers/base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/sentry_sdk/integrations/django/views.py", line 67, in sentry_wrapped_callback
    return callback(request, *args, **kwargs)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/home/alex/Developer/blossom-backend/blossom/recordings/views.py", line 819, in get
    youtube_video_upload(video_url, recording)
  File "/home/alex/Developer/blossom-backend/blossom/recordings/utils.py", line 791, in youtube_video_upload
    streams = yt.streams
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 321, in streams
    return StreamQuery(self.fmt_streams)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 214, in fmt_streams
    if "adaptive_fmts" in self.player_config_args:
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 188, in player_config_args
    self._player_config_args = self.vid_info
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 291, in vid_info
    return dict(parse_qsl(self.vid_info_raw))
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/__main__.py", line 109, in vid_info_raw
    self._vid_info_raw = request.get(self.vid_info_url)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/request.py", line 53, in get
    response = _execute_request(url, headers=extra_headers, timeout=timeout)
  File "/home/alex/.local/share/virtualenvs/blossom-backend-FLIGhEMr/lib/python3.9/site-packages/pytube/request.py", line 37, in _execute_request
    return urlopen(request, timeout=timeout)  # nosec
  File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 523, in open
    response = meth(req, response)
  File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 632, in http_response
    response = self.parent.error(
  File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 561, in error
    return self._call_chain(*args)
  File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/urllib/request.py", line 494, in _call_chain
    result = func(*args)
  File "/home/alex/.pyenv/versions/3.9.0/lib/python3.9/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
  • Pytube version 10.9.3

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 41
  • Comments: 82 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I can’t fix this tonight, I will try to work on it tomorrow

Heads up for those following this thread:

The upcoming fix will require authentication for age-restricted videos. For end users, this will prompt the user to go to a webpage and enter a code to allow access to their account. There does not appear to be a way around this, as YouTube is actively killing off the endpoint we used to rely on. I don’t think that you will need to make changes to your code, unless you’re accessing unusual parts of the YouTube object.

For those of you who are commenting, “I have the same error” or “same error” and then showing it’s only the HTTP Error 404: Not Found, can you please not?

I’m not trying to be rude but it’s already clear that we’re all having the same issue. Adding such comment to this thread is not adding any value to those who are following this thread and trying to get updates and also to the contributors who are trying to solve this problem.

let us know the updates asap. our project is delaying due to this.

I don’t want to speak for the main contributor of this project, but this type of passive-aggressive demand is not welcome in any libre and open-source project. The contributors do not owe you anything, as specified in the license.

That being said, your actual contributions to the project are certainly always welcome.

Sorry I came out a bit rude, but libre and open-source projects contributors expect a bit more maturity from their users.

The fix for this has been pushed to pypi as v11.0.0, so you should be able to install it normally with python -m pip install --upgrade pytube

Do we have an update on this, since this being an awesome library and with a critical issue like this one, I am having an impact on an already running app. Request to please kindly provide an update on this issue. Also, thanks for the awesome work you guys are doing!

Update: I made a couple slight changes to Zeecka’s solution that should help with the age restrictions. I believe the current version will now work correctly for most age-restricted videos without needing to authenticate. There are certain age-restricted videos that are even more restricted than others that will require authentication, but these videos are very uncommon.

If you are able to, please install the experimental version, test it out, and let us know if there are any unexpected errors. If you run into an AgeRestrictedError exception, then you are probably testing against a video that has the higher level of age-restriction, and will need to authenticate. You can do that as follows:

yt = YouTube(url, use_oauth=True)

The first time that you run this code with the use_oauth argument, it will prompt you to visit a URL and input a code to authorize access to your account. This generates an authorization and refresh OAuth token, which are then stored on the machine running the code. Doing this introduces a potential security risk. Specifically, those tokens are scoped to YouTube, which means that if they get exposed, somebody could perform certain actions as though they were your account. Although this does not give direct access to your account, it does allow access to certain features. I’m a little fuzzy on exactly what this scope allows, but YouTube’s public API states that the scope allows the token to Manage your YouTube account. If you do NOT want to store these locally, you can pass another argument, allow_oauth_cache=False to prevent them from being stored on disk.

You can install the experimental fix to test it with python -m pip install git+https://github.com/Zeecka/pytube@fix_1060, as @shohamtal says above.

For those of you who are commenting, “I have the same error” or “same error” and then showing it’s only the HTTP Error 404: Not Found, can you please not? I’m not trying to be rude but it’s already clear that we’re all having the same issue. Adding such comment to this thread is not adding any value to those who are following this thread and trying to get updates and also to the contributors who are trying to solve this problem.

Even more thread with same 404 will come… That’s because its a popular library. And people wants it to be fixed soon. Their project depends on this library. All we can do is fix it for all soon.

This is just proving my point.

We all know this is a popular library. We all want the same goal of having it fixed. We all have projects that depend on this library. The contributors are doing what they can to help us all, but just as @billsioros had referenced to a previous comment made by @glubsy, the contributors also don’t owe us anything.

Please stop with this commentary, as it adds absolutely no value to those who are trying to receives updates and to the contributors who are trying to come up with a fix for everyone.

let us know the updates asap. our project is delaying due to this.

I don’t want to speak for the main contributor of this project, but this type of passive-aggressive demand is not welcome in any libre and open-source project. The contributors do not owe you anything, as specified in the license.

That being said, your actual contributions to the project are certainly always welcome.

Sorry I came out a bit rude, but libre and open-source projects contributors expect a bit more maturity from their users.

You are absolutely right Sir. Please accept humble apologies. I know we people(dev) working hard to improve open-source projects to enhance technology and I admire that. Thanks for letting me know, I’ll keep that in mind.

My apologies. Thanks for pointing this out. Being exhausted by trying solutions is no reason to send a request that sounds like a polite demand. I’ll surely learn from this!

Best.

@rishabh3354 actually this is expected since YouTube always block apis like these and make updates on them from time to time.

I can’t fix this tonight, I will try to work on it tomorrow

let us know the updates asap. our project is delaying due to this.

@clo0wn this solution will work for unrestricted videos without authentication, we’re just seeing weird errors on some videos.

You can test Zeecka’s experimental solution. Worked great for me: pip install git+https://github.com/Zeecka/pytube@fix_1060

Had to change my code to explicit download mp4 format, otherwise it downloaded 3gp format: YouTube("https://www.youtube.com/watch?v=7kZqas35FTA").streams.filter(progressive=True, file_extension='mp4').first().download()

I have the same error too!! urllib.error.HTTPError: HTTP Error 404: Not Found

If yesterday one of the 2-3 requests was a success, today all requests failed. I tried to handle it in the cycle, and if the request fails then repeat the request. Else return stream, but now all requests fail.

For those of you who are commenting, “I have the same error” or “same error” and then showing it’s only the HTTP Error 404: Not Found, can you please not?

I’m not trying to be rude but it’s already clear that we’re all having the same issue. Adding such comment to this thread is not adding any value to those who are following this thread and trying to get updates and also to the contributors who are trying to solve this problem.

Even more thread with same 404 will come… That’s because its a popular library. And people wants it to be fixed soon. Their project depends on this library. All we can do is fix it for all soon.

Hello everyone, I have same problem!

Its been more than a week. No sign of hope… 🥺😟😒😒😒. Pytube was one of my favorite libraries. It can’t be Dead. 😒😒😒😒

Same problem here aswell when using

yt = YouTube(Link)
vids = yt.streams.filter(only_audio=True)

Traceback:

  File "Path\Youtube Downloader\DownloadApp.pyw", line 60, in run
    result = self.fn(*self.args, **self.kwargs)
  File "Path\Youtube Downloader\DownloadApp.pyw", line 184, in Download
    vids = yt.streams.filter(only_audio=True)
  File "Path\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 321, in streams
    return StreamQuery(self.fmt_streams)
  File "Path\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 214, in fmt_streams
    if "adaptive_fmts" in self.player_config_args:
  File "Path\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 188, in player_config_args
    self._player_config_args = self.vid_info
  File "Path\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 291, in vid_info
    return dict(parse_qsl(self.vid_info_raw))
  File "Path\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 109, in vid_info_raw
    self._vid_info_raw = request.get(self.vid_info_url)
  File "Path\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\request.py", line 53, in get
    response = _execute_request(url, headers=extra_headers, timeout=timeout)
  File "Path\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\request.py", line 37, in _execute_request
    return urlopen(request, timeout=timeout)  # nosec
  File "Path\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen
    return opener.open(url, data, timeout)
  File "Path\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 523, in open
    response = meth(req, response)
  File "Path\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 632, in http_response
    response = self.parent.error(
  File "Path\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 561, in error
    return self._call_chain(*args)
  File "Path\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain
    result = func(*args)
  File "Path\AppData\Local\Programs\Python\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```

Its been more than a week. No sign of hope… 🥺😟😒😒😒. Pytube was one of my favorite libraries. It can’t be Dead. 😒😒😒😒

It’s not dead, just having problems trying to fix it, and I only have a few hours each night to work on it. Most of the updates so far can be found in #1067. Please do not post in that pull request, however, unless you are contributing to the fix.

I can’t fix this tonight, I will try to work on it tomorrow

let us know the updates asap. our project is delaying due to this.

Streamlink is pretty reliable for downloading Youtube videos, it’s just missing many PyTube features like checking video file size, checking video length, getting progress callback, etc. Maybe add it as a backup to your own project?

You can even get back most of PyTube’s features by using Youtube’s real API with an API key.

@ rishabh3354 na verdade, isso é esperado, já que o YouTube sempre bloqueia aplicativos como esses e faz atualizações neles de vez em quando.

Portanto, deve haver uma solução para isso … Na verdade, é bastante irritante … por favor, sugira uma solução.

This error already happened in the past, basically youtube updated the URLs, so PyTube couldn’t download the video, at the time the solution was a new Pytube update, at the moment I’m not having problems in my application with this error, maybe that’s just it is happening to some people.

Hey guys, I’m getting HTTP 410 Gone but the video is definitely not gone. Maybe a bug?

Traceback (most recent call last):
  File "get_youtube_video.py", line 57, in <module>
    main()
  File "get_youtube_video.py", line 42, in main
    stream = yt.streams.filter(progressive=True, file_extension='mp4').first()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytube/__main__.py", line 321, in streams
    return StreamQuery(self.fmt_streams)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytube/__main__.py", line 214, in fmt_streams
    if "adaptive_fmts" in self.player_config_args:
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytube/__main__.py", line 188, in player_config_args
    self._player_config_args = self.vid_info
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytube/__main__.py", line 291, in vid_info
    return dict(parse_qsl(self.vid_info_raw))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytube/__main__.py", line 109, in vid_info_raw
    self._vid_info_raw = request.get(self.vid_info_url)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytube/request.py", line 53, in get
    response = _execute_request(url, headers=extra_headers, timeout=timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytube/request.py", line 37, in _execute_request
    return urlopen(request, timeout=timeout)  # nosec
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 641, in http_response
    'http', request, response, code, msg, hdrs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 410: Gone

To clarify, this is with pip install git+https://github.com/Zeecka/pytube@fix_1060

I can’t fix this tonight, I will try to work on it tomorrow

https://github.com/ytdl-org/youtube-dl are able to do it by parsing the webpage.

@must-defend-500 I’m hoping to get to it tomorrow. I need to fix a bunch of unit tests, and it’s taking a while (most of the old ones relied on data generated by the old get_vid_info url, so now that objects are being created in a different way, its causing issues with our mock objects)

Just so you know, even if I did the initial PR, @tfdahlin was already aware of the workaround and worked on the biggest part of the fix (oauth / Age restriction bypass). Thank you for your work.

@rishabh3354 as @glubsy previously stated.

I don’t want to speak for the main contributor of this project, but this type of passive-aggressive demand is not welcome in any libre and open-source project. The contributors do not owe you anything, as specified in the license.

That being said, your actual contributions to the project are certainly always welcome.

Sorry I came out a bit rude, but libre and open-source projects contributors expect a bit more maturity from their users.

Hi, just confirming: I have the same error (as it seems with any youtube link).

urllib.error.HTTPError: HTTP Error 404: Not Found

I hope the solution to that problem will be found soon, as it’s great lib, fast and easy to use.

I have tried fix_1060 Able to download videos. But there are errors for videos where key ‘contentLength’ is missing from Stream. Traceback (most recent call last): File “c:/Users/username/nlp_repo/AzureOCR/TestPython.py”, line 15, in yt.streams.filter(file_extension = “mp4”) File “C:\Users\username\Anaconda3\lib\site-packages\pytube__main__.py”, line 286, in streams return StreamQuery(self.fmt_streams) File “C:\Users\username\Anaconda3\lib\site-packages\pytube__main__.py”, line 192, in fmt_streams video = Stream( File “C:\Users\username\Anaconda3\lib\site-packages\pytube\streams.py”, line 62, in init self._filesize: Optional[int] = stream[‘contentLength’] # filesize in bytes KeyError: ‘contentLength’ Which I fixed in C:\Users\username\Anaconda3\lib\site-packages\pytube\streams.py by placing a check at line 62 ``

if 'contentLength' in stream:
            self._filesize: Optional[int] = stream['contentLength']  # filesize in bytes
        else:
            self._filesize: Optional[int] = 0

After that It worked for me. I am not sure why some video streams is missing this important property.

Can you provide the video that you got this error on?

I tried this link : https://www.youtube.com/watch?v=vdFJ9lNdpwk

code i used below :

yt = YouTube(link)
yt.streams.filter(file_extension = "mp4")

ys = yt.streams.get_by_itag(22)
ys.download(dest_path ,filename=videofilename)

Error after running above code : Traceback (most recent call last): File “c:/Users/username/nlp_repo/AzureOCR/TestPython.py”, line 12, in <module> yt.streams.filter(file_extension = “mp4”) File “C:\Users\username\Anaconda3\lib\site-packages\pytube_main_.py”, line 286, in streams return StreamQuery(self.fmt_streams) File “C:\Users\username\Anaconda3\lib\site-packages\pytube_main_.py”, line 192, in fmt_streams video = Stream( File “C:\Users\username\Anaconda3\lib\site-packages\pytube\streams.py”, line 62, in init self._filesize: Optional[int] = stream[‘contentLength’] # filesize in bytes KeyError: ‘contentLength’

shared code was working earlier 20 days ago

let us know the updates asap. our project is delaying due to this.

I don’t want to speak for the main contributor of this project, but this type of passive-aggressive demand is not welcome in any libre and open-source project. The contributors do not owe you anything, as specified in the license.

That being said, your actual contributions to the project are certainly always welcome.

Sorry I came out a bit rude, but libre and open-source projects contributors expect a bit more maturity from their users.

Yes, you are Absoutly right, but you didn’t answer his question.?

@tfdahlin Please post an updated fix. This is stalling my work. I’m not able to understand why this is happening.

I am getting the same error, tried with python 3.9. 3.8. 3.7. No solution.

Pytube version: pytube-10.9.3 code:

yt = YouTube('https://www.youtube.com/watch?v=LXWKNN0lPsQ')
for i in yt.streams.filter(progressive=True, file_extension='mp4', type="video").order_by('resolution').desc():
    print(i)

error:

HTTPError: HTTP Error 404: Not Found
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-8-5fc1e3e7ffe6> in <module>
      1 yt = YouTube('https://www.youtube.com/watch?v=LXWKNN0lPsQ')
----> 2 for i in yt.streams.filter(progressive=True, file_extension='mp4', type="video").order_by('resolution').desc():
      3     print(i)
      4     print(type(i))

~\Anaconda3\lib\site-packages\pytube\__main__.py in streams(self)
    319         """
    320         self.check_availability()
--> 321         return StreamQuery(self.fmt_streams)
    322 
    323     @property

~\Anaconda3\lib\site-packages\pytube\__main__.py in fmt_streams(self)
    212         # https://github.com/pytube/pytube/issues/165
    213         stream_maps = ["url_encoded_fmt_stream_map"]
--> 214         if "adaptive_fmts" in self.player_config_args:
    215             stream_maps.append("adaptive_fmts")
    216 
~\Anaconda3\lib\site-packages\pytube\__main__.py in player_config_args(self)
    186             return self._player_config_args
    187 
--> 188         self._player_config_args = self.vid_info
    189         # On pre-signed videos, we need to use get_ytplayer_config to fix
    190         #  the player_response item

~\Anaconda3\lib\site-packages\pytube\__main__.py in vid_info(self)
    289         :rtype: Dict[Any, Any]
    290         """
--> 291         return dict(parse_qsl(self.vid_info_raw))
    292 
    293     @property

~\Anaconda3\lib\site-packages\pytube\__main__.py in vid_info_raw(self)
    107         if self._vid_info_raw:
    108             return self._vid_info_raw
--> 109         self._vid_info_raw = request.get(self.vid_info_url)
    110         return self._vid_info_raw
    111 

~\Anaconda3\lib\site-packages\pytube\request.py in get(url, extra_headers, timeout)
     51     if extra_headers is None:
     52         extra_headers = {}
---> 53     response = _execute_request(url, headers=extra_headers, timeout=timeout)
     54     return response.read().decode("utf-8")
     55 
~\Anaconda3\lib\site-packages\pytube\request.py in _execute_request(url, method, headers, data, timeout)
     35     else:
     36         raise ValueError("Invalid URL")
---> 37     return urlopen(request, timeout=timeout)  # nosec
     38 
     39 

~\Anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    220     else:
    221         opener = _opener
--> 222     return opener.open(url, data, timeout)
    223 
    224 def install_opener(opener):

~\Anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
    529         for processor in self.process_response.get(protocol, []):
    530             meth = getattr(processor, meth_name)
--> 531             response = meth(req, response)
    532 
    533         return response

~\Anaconda3\lib\urllib\request.py in http_response(self, request, response)
    638         # request was successfully received, understood, and accepted.
    639         if not (200 <= code < 300):
--> 640             response = self.parent.error(
    641                 'http', request, response, code, msg, hdrs)
    642 
~\Anaconda3\lib\urllib\request.py in error(self, proto, *args)
    567         if http_err:
    568             args = (dict, 'default', 'http_error_default') + orig_args
--> 569             return self._call_chain(*args)
    570 
    571 # XXX probably also want an abstract factory that knows when it makes

~\Anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
    500         for handler in handlers:
    501             func = getattr(handler, meth_name)
--> 502             result = func(*args)
    503             if result is not None:
    504                 return result

~\Anaconda3\lib\urllib\request.py in http_error_default(self, req, fp, code, msg, hdrs)
    647 class HTTPDefaultErrorHandler(BaseHandler):
    648     def http_error_default(self, req, fp, code, msg, hdrs):
--> 649         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    650 
    651 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 404: Not Found

Hoping to recieve a fix soon!

i downloaded dash stream video and found extension is missing in the downloaded files. Previously extension (for eg .mp4 or.webm ) is automatically included in the downloaded videos. I dont know if its a bug or new feature but my project breaks with this. i am using ubuntu 20.04 @Zeecka

@rishabh3354 This behavior changed in v10.9.3, and should only happen if you’re using the filename argument when downloading. When you specify a custom filename, you should now include the extension as part of the filename (which you can access with stream.subtype). If you do not use the filename argument, a filename will be automatically generated that correctly includes the extension.

python -m pip install git+https://github.com/Zeecka/pytube@fix_1060 Worked for me. Using the regular pip install pytube isn’t. Will the fix be implemented into the main repo?

Yes, it will, but it needs to be tested more thoroughly before I push it there, hence why I’m asking for help testing.

Atualização: fiz algumas pequenas alterações na solução do Zeecka que devem ajudar com as restrições de idade. Acredito que a versão atual agora funcionará corretamente para a maioria dos vídeos com restrição de idade, sem a necessidade de autenticação. Há alguns vídeos com restrição de idade que são ainda mais restritas do que outros que vai exigem autenticação, mas esses vídeos são muito incomuns.

Se puder, instale a versão experimental, teste-a e informe-nos se houver algum erro inesperado. Se você encontrar uma AgeRestrictedErrorexceção, provavelmente está testando um vídeo que tem o nível mais alto de restrição de idade e precisará ser autenticado. Você pode fazer isso da seguinte maneira:

yt  =  YouTube ( url , use_oauth = True )

Na primeira vez que você executar este código com o use_oauthargumento, ele solicitará que você visite um URL e insira um código para autorizar o acesso à sua conta. Isso gera uma autorização e um token OAuth de atualização , que são armazenados na máquina que executa o código. Fazer isso apresenta um risco potencial de segurança . Especificamente, esses tokens têm como escopo o YouTube , o que significa que, se forem expostos, alguém pode realizar certas ações como se fossem sua conta. Embora isso não conceda acesso direto à sua conta, permite o acesso a certos recursos. Estou um pouco confuso sobre exatamente o que esse escopo permite, mas a API pública do YouTube afirma que o escopo permite que o tokenManage your YouTube account. Se você NÃO deseja armazená-los localmente, pode passar outro argumento, allow_oauth_cache=Falsepara evitar que sejam armazenados no disco.

Você pode instalar a correção experimental para testá-la python -m pip install git+https://github.com/Zeecka/pytube@fix_1060, como @shohamtal disse acima.

I’m glad you had a solution for the error 🙌🙌, I just have a doubt that is: If in my code I don’t put the use_oauth, and put it to download normally nothing will be stored on my machine right?

Do we have an update on this, since this being an awesome library and with a critical issue like this one, I am having an impact on an already running app. Request to please kindly provide an update on this issue. Also, thanks for the awesome work you guys are doing!

Same here, actually impacting my project too. But anyways i am sure they will make it. thanks guys

@tfdahlin good catch, Ive got python and python3 issues on my computer. I don’t know why I can’t intsall it from Github. I’ll just wait for you guys to merge with master. Any sense when that might happen?

python -m pip install git+https://github.com/Zeecka/pytube@fix_1060 worked for me, thank you SO MUCH @tfdahlin. I will keep testing it out and let you know if i encounter any issues.

I’m glad you had a solution for the error 🙌🙌, I just have a doubt that is: If in my code I don’t put the use_oauth, and put it to download normally nothing will be stored on my machine right?

That is correct. Nothing is stored on your machine if you don’t include the use_oauth argument.

I have tried fix_1060 Able to download videos. But there are errors for videos where key ‘contentLength’ is missing from Stream. Traceback (most recent call last): File “c:/Users/username/nlp_repo/AzureOCR/TestPython.py”, line 15, in yt.streams.filter(file_extension = “mp4”) File “C:\Users\username\Anaconda3\lib\site-packages\pytube__main__.py”, line 286, in streams return StreamQuery(self.fmt_streams) File “C:\Users\username\Anaconda3\lib\site-packages\pytube__main__.py”, line 192, in fmt_streams video = Stream( File “C:\Users\username\Anaconda3\lib\site-packages\pytube\streams.py”, line 62, in init self._filesize: Optional[int] = stream[‘contentLength’] # filesize in bytes KeyError: ‘contentLength’

Which I fixed in C:\Users\username\Anaconda3\lib\site-packages\pytube\streams.py by placing a check at line 62 ``

if 'contentLength' in stream:
            self._filesize: Optional[int] = stream['contentLength']  # filesize in bytes
        else:
            self._filesize: Optional[int] = 0

After that It worked for me. I am not sure why some video streams is missing this important property.

I added a fix for this in #1067. Still trying to figure out how the cipher calculation stuff broke though.

Here’s the Dockerfile which built this software:

FROM python:3.7-slim
WORKDIR /srv
COPY requirements.txt ./
RUN apt update && apt upgrade -y
RUN apt install -y bash ffmpeg devscripts
RUN pip3 install --no-cache-dir --upgrade pip && pip3 install --no-cache-dir -r requirements.txt
RUN cd /tmp && git clone https://github.com/Zeecka/pytube && cd pytube && git checkout fix_1060
RUN pip3 install --upgrade git+file:/tmp/pytube
....

We really do appreciate your hard work, Sir! Hopefully, the next update will be released soon.

Its been more than a week. No sign of hope… 🥺😟😒😒😒. Pytube was one of my favorite libraries. It can’t be Dead. 😒😒😒😒

It’s not dead, just having problems trying to fix it, and I only have a few hours each night to work on it. Most of the updates so far can be found in #1067. Please do not post in that pull request, however, unless you are contributing to the fix.