Fluxy
Fluxy

Reputation: 2978

Download video from YouTube: HTTPError: HTTP Error 404: Not Found

I use pytube to donwload video files from YouTube. The code was working fine, but recently started throwing HTTPError: HTTP Error 404: Not Found. How can I fix it? Or is there any other similar Python library that can be used to download videos from YouTube?

from pytube import YouTube

def downloadVideoFromYoutube(videourl, path):
    yt = YouTube(videourl)
    yt = yt.streams.filter(progressive=True, file_extension="mp4").order_by("resolution").desc().first()
    if not os.path.exists(path):
        os.makedirs(path)
    yt.download(path)

Error:

/anaconda/envs/azureml_py36/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs) 648 class HTTPDefaultErrorHandler(BaseHandler): 649 def http_error_default(self, req, fp, code, msg, hdrs): --> 650 raise HTTPError(req.full_url, code, msg, hdrs, fp) 651 652 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 404: Not Found

I followed recommendations from this thread but it did not work for me:

neither:

pip install pytube==10.8.5

nor:

pip install git+https://github.com/ssuwani/pytube

nor:

python -m pip install --upgrade pytube

Upvotes: 0

Views: 245

Answers (2)

Akash Sharma
Akash Sharma

Reputation: 184

This is a bug with pytube, it has happened previously and got fixed but looks like it may have been reintroduced. You could always look into another library e.g. youtube_dl or ytpy or just try uninstalling pytube and install pytube3 instead. (pip uninstall pytube) (pip install pytube3)

Upvotes: 0

Ohm Dios
Ohm Dios

Reputation: 43

Anaconda Environment May throw 'HTTP Error'. Run py code directly in cmd for example in windows :> python yourfilname.py

Upvotes: 0

Related Questions