Python 错误:urllib.error.HTTPError:HTTP 错误 404:未找到

时间:2021-06-01 21:12:36

标签: python

我正在为学校构建一个python项目(YouTube视频下载器),但是当我运行它时,出现这个错误:urllib.error.HTTPError: HTTP Error 404: Not Found 我已经尝试过其他人的其他代码,但没有人成功,我认为是我的电脑。我能做什么?

代码如下:

from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from pytube import YouTube #pip install pytube3

Folder_Name = ""

#file location
def openLocation():
    global Folder_Name
    Folder_Name = filedialog.askdirectory()
    if(len(Folder_Name) > 1):
    locationError.config(text=Folder_Name,fg="green")

else:
    locationError.config(text="Please Choose Folder!!",fg="red")

#donwload video
def DownloadVideo():
    choice = ytdchoices.get()
    url = ytdEntry.get()

if(len(url)>1):
    ytdError.config(text="")
    yt = YouTube(url)

    if(choice == choices[0]):
        select = yt.streams.filter(progressive=True).first()

    elif(choice == choices[1]):
        select = yt.streams.filter(progressive=True,file_extension='mp4').last()

    elif(choice == choices[2]):
        select = yt.streams.filter(only_audio=True).first()

    else:
        ytdError.config(text="Paste Link again!!",fg="red")


#download function
select.download(Folder_Name)
ytdError.config(text="Download Completed!!")



root = Tk()
root.title("YTD Downloader")
root.geometry("350x400") #set window
root.columnconfigure(0,weight=1)#set all content in center.

#Ytd Link Label
ytdLabel = Label(root,text="Enter the URL of the Video",font=("jost",15))
ytdLabel.grid()

#Entry Box
ytdEntryVar = StringVar()
ytdEntry = Entry(root,width=50,textvariable=ytdEntryVar)
ytdEntry.grid()

#Error Msg
ytdError = Label(root,text="Error Msg",fg="red",font=("jost",10))
ytdError.grid()

#Asking save file label
saveLabel = Label(root,text="Save the Video File",font=("jost",15,"bold"))
saveLabel.grid()

#btn of save file
saveEntry = Button(root,width=10,bg="red",fg="white",text="Choose Path",command=openLocation)
saveEntry.grid()

#Error Msg location
locationError = Label(root,text="Error Msg of Path",fg="red",font=("jost",10))
locationError.grid()

#Download Quality
ytdQuality = Label(root,text="Select Quality",font=("jost",15))
ytdQuality.grid()

#combobox
choices = ["720p","144p","Only Audio"]
ytdchoices = ttk.Combobox(root,values=choices)
ytdchoices.grid()

#donwload btn
downloadbtn = Button(root,text="Donwload",width=10,bg="red",fg="white",command=DownloadVideo)
downloadbtn.grid()

#developer Label
developerlabel = Label(root,text="Dream Developers",font=("jost",15))
developerlabel.grid()
root.mainloop()

这里是终端: Terminal

Terminal

1 个答案:

答案 0 :(得分:1)

我测试过:代码不适用于 pytube-10.4.1,但适用于最新的 pytube-10.8.3

似乎 YouTube 更改了服务器上的某些内容,它需要更改 pytube