I made a simple 3 line project with pyTube library. All it does is download a video from YT. With it I usually download videos of handball games which are around 100 minutes long. It all worked fine 7 days ago when i last used it but now it throws an "HTTP Error 400: Bad Request" error.
from pytube import YouTube
youtubeObject = YouTube('https://www.youtube.com/watch?v=DASMWPUFFP4')
youtubeObject = youtubeObject.streams.get_highest_resolution()
youtubeObject.download('D:\\Utakmice')
It works with a shorter videos but it doesnt work with any other videos of the similar length (~100mins). I tried upgrading pyTube library and cleaning browser cache but it didnt help. Tried to dig dipper into the urllib but couldnt find anything there either. The error I am getting is:
urllib.error.HTTPError: HTTP Error 400: Bad Request
Couldnt find any solution online so any help is appreciated. Thanks in advance.
I found an issue about this on the pytube GitHub. The fix requiered the change of certain client versions in innertube.py file. The link to the issue: https://github.com/pytube/pytube/issues/1894#issue-2180600881
I tried this and it worked fine for me
pip install pytubefix
from pytubefix import YouTube
from pytubefix.cli import on_progress
url = "url"
yt = YouTube(url, on_progress_callback = on_progress)
print(yt.title)
ys = yt.streams.get_highest_resolution()
ys.download()
#This is a link to the library. https://pypi.org/project/pytubefix/
This is a recent issue that has been raised in the Pytube project: issue link
In the meantime, you can use a new package as suggested by Tomtunn. It serves a similar purpose named pytubefix
I hope this solves your issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With