Error ‘Key’ with Pytube

What is pytube?

It is a module for Python that let you download a video with pytube.

In this page I will try to take see how to fix some issues that sometimes occur with this module.

Updated errors: 10/09/2019

The latest error was a

KeyError: ‘title’

Searching how to fix the error I made this, it’s rough but it works.

Go in the pytube dir, making this

Go in the directory site-packages of your Python installation (see the video if you do not know where it is) and go into the pytube folder. Open with an editor the streams.py file. Go to line 176, comment it:

        #title = self.player_config_args['title']

Go to line 177 and make it like this

        filename = safe_filename("title")

Save it and then test it running this code (you will be asked to input the address of the youtube video (right click on the video to have it) … dowload only no copyighted things).

from pytube import YouTube
url = input("Video url: > ")
yt = YouTube(url)
stream = yt.streams.first()
stream.download() # this will download in your current working Dir

It will work

Updated: 10.9.2019

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.