pytube: "urllib.error.HTTPError: HTTP Error 404: Not Found" when downloading using pytube
I’ve been getting this error ever since I downloaded pytube, which was only two weeks ago, but it keeps getting worse. At least 1 in 30 downloads will give me the error “urllib.error.HTTPError: HTTP Error 404: Not Found”
When I run the loop using the same YouTube link and Download location:
import pytube
for i in range(50):
out_file = pytube.YouTube("https://www.youtube.com/watch?v=yHwGIA4VeOc").streams.first().download("D:\Music")
print("Done")
I get the error “urllib.error.HTTPError: HTTP Error 404: Not Found” at least once during the loop. Sometimes it will give the error on the 5th download, sometimes on the 43rd. It is random. If I’m lucky it will download them all successfully, but that almost never happens.
I’ve tried putting a delay between downloads and looping through a list of links instead of using the same link for each download, but neither worked.
There is an old issue from 2019, where people have left comments having the same issue within the last two weeks, so I’m not the only one.
Information:
- Python 3.9.5
- Pytube 10.8.1
- I used “python -m pip install git+https://github.com/pytube/pytube” to download pytube
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 48 (1 by maintainers)
The reason that it looks like it’s making a request twice is because of the 301 redirect. The library only makes the request once, but behind the scenes httplib is making a request to
youtube.com/
, getting redirected towww.youtube.com
, and then proceeding with the request there.@ the rest of y’all, I’m going to spend tonight seeing if I can get this fixed
Problem is
get_video_info
, change code inpytube/extract.py
not
PR/996
Not working, I’m also getting the “KeyError: ‘player_response’” error
EDIT: I fixed it by removing [‘player_response’] on line 190 in
__main__.py
So it should look something like this:if 'streamingData' not in self.player_config_args:
But I don’t know if this is a proper fix.Update: I think I found a way around using the
get_video_info
url, I’m working on updating supporting functions that relied on this information now.python -m pip install --upgrade pytube
should install the fix now. If there are further issues with v10.8.2, please open a new ticket so they get documented properlyty for all the tracebacks, it looks like it is an issue with just the vid info url, I’ll see if I can investigate what’s causing it sometime this week
Huge thank you to @Ssuwani for the proposed solution, and @drwjf for adapting it to the existing code convention while I was unavailable
Solution works for me. I saw some responses with “player_response” being an error , just be sure you have this : return “https://www.youtube.com/get_video_info?html5=1&video_id=” + params[‘video_id’] Notice the lack of “amp;” , if you have that the reponse comes back as “status: fail” and hence no player_response in returned response
Ssuwani fix +This fixed it for me
Still in progress, have to sleep for now. Currently running into a 403 issue if anybody wants to check out my branch to try and solve it. Otherwise I’ll try resume work on this tomorrow afternoon
Can we please re-open this issue as it seems that it has not been fully resolved ? I’m facing the same problem as @SergeZ23. Thanks in advance!
I get the same error on certain videos with pytube version 10.8.4
I’m downloading streams that are not progressive, sometimes it would download the video stream and fail on the audio, sometimes it would fail on the video stream. I’ve also seen a case where on the first try I was able to download the video stream and failed on the audio, but on the second try with the same video, the error has occured while trying to download the video stream that has been downloaded successfully before that. The code is:
Solved my problem, thanks friend
Since somebody opened a new issue for the current 404 problems, I’m going to leave this issue closed and use that one instead.
Hey folks; I’m going to merge the PR @drwjf made once the CI tests pass. Expect v10.8.2 to be on pypi in the next 10 minutes or so.
works not for me, get error ‘player respone’ 😦
@tfdahlin I’ve been getting the same error using the CLI (so I’m not looping through multiple urls at once like @FlubOtic), but the error still seems to occur randomly, and I’ve found that if I try to download the same video a few times in a row the download will eventually succeed (after failing with the above error on the first couple of tries).
Can confirm too.
Full traceback:
My code is quite simple. Downloading a list of videos.