0

Here's my code I keep get an error but I don't what and why the error is there

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()

Thats my code and when I tried to paste the link of a YouTube vid, it would just give an error message saying

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)>

I'm fairly new and I'm so confused, if you could help me that would be very appreciated because I do not understand what this means

coderoftheday
  • 1,987
  • 4
  • 7
  • 21
Jennieee
  • 15
  • 5
  • I didn't get any errors. Also, make sure you are using the correct path. If the problem persists post the link for the video you got this error. – JacksonPro Dec 12 '20 at 13:47
  • May be this question [urllib-and-ssl-certificate-verify-failed-error](https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error) help. – acw1668 Dec 13 '20 at 07:06
  • @JacksonPro have you tried pasting a link? – Jennieee Dec 13 '20 at 12:29
  • @acw1668 thankyou, that solved the first part of the error, but I still have the other error – Jennieee Dec 13 '20 at 12:30
  • @Dylan Yes, your code works fine for me. I have posted an answer tell me if that works – JacksonPro Dec 13 '20 at 13:41

1 Answers1

0

Here try this:

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()
JacksonPro
  • 3,135
  • 2
  • 6
  • 29
  • Try these YouTube link: https://www.youtube.com/watch?v=xWOoBJUqlbI or https://www.youtube.com/watch?v=ridS396W2BY – JacksonPro Dec 13 '20 at 13:40