【问题标题】:I need help for my YouTube Video Downloader using tkinter and pytube in Python我需要帮助我的 YouTube 视频下载器在 Python 中使用 tkinter 和 pytube
【发布时间】:2020-12-12 10:11:29
【问题描述】:

这是我的代码,我一直收到错误,但我不知道错误是什么以及为什么会出现错误

from pytube import YouTube
from tkinter import *
from tkinter import Tk, font

root = Tk()
root.geometry('700x250')
root.title('YouTube Downloader')

link_here = Label(root, text="Paste Here", font=("courier",40,))
link_here.place(x=220,y=40)

linkbruh = StringVar()
pasted = Entry(root,width=60,textvariable=linkbruh)
pasted.place(x=80,y=120)

def download():
    a = (str(linkbruh.get()))
    vid = YouTube(a).streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
    vid.download('/downloadhere')

Button(root,text="Download Video", width=20, bg="black", fg="gray", command=download).place(x=250,y=170)

root.mainloop()

这是我的代码,当我尝试粘贴 YouTube 视频的链接时,它只会给出一条错误消息

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1350, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1240, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1286, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1235, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1006, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 946, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1409, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
    return self.func(*args)
  File "/Users/dylanbradley/PycharmProjects/ytconvert/main.py", line 18, in download
    vid = YouTube(a).streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
  File "/Users/dylanbradley/PycharmProjects/ytconvert/venv/lib/python3.8/site-packages/pytube/__main__.py", line 91, in __init__
    self.prefetch()
  File "/Users/dylanbradley/PycharmProjects/ytconvert/venv/lib/python3.8/site-packages/pytube/__main__.py", line 162, in prefetch
    self.watch_html = request.get(url=self.watch_url)
  File "/Users/dylanbradley/PycharmProjects/ytconvert/venv/lib/python3.8/site-packages/pytube/request.py", line 36, in get
    return _execute_request(url).read().decode("utf-8")
  File "/Users/dylanbradley/PycharmProjects/ytconvert/venv/lib/python3.8/site-packages/pytube/request.py", line 24, in _execute_request
    return urlopen(request)  # nosec
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1393, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1353, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)>

我是新手,很困惑,如果您能帮助我,将不胜感激,因为我不明白这是什么意思

【问题讨论】:

  • 我没有收到任何错误。另外,请确保您使用的是正确的路径。如果问题仍然存在,请发布您收到此错误的视频链接。
  • 可能是这个问题urllib-and-ssl-certificate-verify-failed-error帮助。
  • @JacksonPro 你试过粘贴链接吗?
  • @acw1668 谢谢,解决了第一部分的错误,但我还有另一个错误
  • @Dylan 是的,你的代码对我来说很好用。我已经发布了一个答案,告诉我这是否有效

标签: python tkinter pytube


【解决方案1】:

这里试试这个:

from pytube import YouTube
from tkinter import *
from tkinter import Tk, font



def download():
    hide()
    a = (str(linkbruh.get()))
    try:
        vid = YouTube(a)
        down = vid.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()
              
        title.config(text=f'title: {vid.title}')
        title.place(x=220, y=230)   

        
        down.download(r'\downloads')   # give your path here              

        error.config(text='Successfully downloaded')
        error.place(x=220, y=210)

        
    except:
        error.config(text='error: Unable to download the video')
        error.place(x=220, y=210)
        return 

def hide():
    title.place_forget()
    error.place_forget()

root = Tk()
root.geometry('700x250')
root.title('YouTube Downloader')

link_here = Label(root, text="Paste Here", font=("courier",40,))
link_here.place(x=220,y=40)

title = Label(root, text='')
title.place(x=220, y=230)

error = Label(root, text='')
error.place(x=220, y=210)

linkbruh = StringVar()
pasted = Entry(root,width=60,textvariable=linkbruh)
pasted.place(x=80,y=120)

Button(root,text="Download Video", width=20, bg="black", fg="gray", command=download).place(x=250,y=170)

root.mainloop()

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-12
  • 1970-01-01
  • 1970-01-01
  • 2018-08-18
  • 2021-07-09
  • 2022-08-19
相关资源
最近更新 更多