英文:
Exception in Tkinter callback Traceback (most recent call last) error
问题
我在Python中遇到了一个奇怪的错误消息,以前正常工作的代码现在出现问题。
应用程序启动后,应该放置YouTube视频链接的窗口出现,但是当我输入链接并点击下载时,会出现错误消息。这段代码以前是可以工作的,我不明白出了什么问题。
以下是错误消息。
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'
以下是我的main.py代码
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()
尝试在线寻找解决方法,但未找到。
英文:
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.
答案1
得分: 0
运行
pip list
查看你所拥有的 pytube 版本。如果低于 15.0.0,则运行
pip uninstall pytube
然后执行
pip install pytube
我测试了你的代码(和我之前有的类似程序)。升级前两者都无法正常工作,但升级后可以正常运行。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论