Search code examples
pythontkinter

Exception in Tkinter callback Traceback (most recent call last) error


I am getting this weird error message in python for the code that used to work properly. The app starts and the window where the youtube video url should be placed is shown, but when I enter the link and click download I get the error message. This code used to work before, I can't seem to get what is wrong. Here is the error message.

    Exception in Tkinter callback
    Traceback (most recent call last):
    File "C:\Users\PC\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 1892, in __call__
    return self.func(*args)
    File "C:\Users\PC\AppData\Local\Programs\Python\Python39\lib\site-packages\customtkinter\windows\widgets\ctk_button.py", line 531, in _clicked
    self._command()
  File "C:\Users\PC\Desktop\youtube converter\main.py", line 17, in Download
    youtubeObject = youtubeObject.streams.get_audio_only()
  File "C:\Users\PC\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 296, in streams
    return StreamQuery(self.fmt_streams)
  File "C:\Users\PC\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 176, in fmt_streams
    stream_manifest = extract.apply_descrambler(self.streaming_data)
  File "C:\Users\PC\AppData\Local\Programs\Python\Python39\lib\site-packages\pytube\__main__.py", line 161, in streaming_data
    return self.vid_info['streamingData']
KeyError: 'streamingData'

Here is my main.py code

import customtkinter

from pytube import YouTube


customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("dark-blue")

root = customtkinter.CTk()

root.geometry("500x350")


def Download():
    youtubeObject = entry.get()
    youtubeObject = YouTube(youtubeObject)
    youtubeObject = youtubeObject.streams.get_audio_only()
    try:
        youtubeObject.download()
    except:
        print("Error!")
    print("Success!")


frame = customtkinter.CTkFrame(master=root)
frame.pack(pady = 20, padx = 60, fill="both", expand = True)


entry = customtkinter.CTkEntry(master=frame, placeholder_text= "URL")
entry.pack(pady=12, padx = 10)

button = customtkinter.CTkButton(master=frame, text="Download", command=Download)
button.pack(pady=12, padx = 10)

root.mainloop()

Tried looking for the fix online but couldn't find one.


Solution

  • Run

    pip list
    

    and see what version of pytube you have. If it's anything less than 15.0.0 then run

    pip uninstall pytube 
    

    followed by

    pip install pytube. 
    

    I tested your code (and a similar program I had). Neither worked before the upgrade, but worked fine afterwards.