我正在尝试使用 PyTube 包下载 youtube 视频,但我无法这样做。我正在使用 Python 3.5 和 pytube 9.2.2。Urllib 在其他程序中没有给我错误,但在这里给我错误。
我正在使用的代码是:
#importing the module
from pytube import YouTube
#where to save
SAVE_PATH = "E:/" #to_do
#link of the video to be downloaded
link="https://www.youtube.com/watch?v=xWOoBJUqlbI"
yt = YouTube(link)
#filters out all the files with "mp4" extension
mp4files = yt.filter('mp4')
yt.set_filename('GeeksforGeeks Video') #to set the name of the file
#get the video with the extension and resolution passed in the get() function
d_video = yt.get(mp4files[-1].extension,mp4files[-1].resolution)
try:
#downloading the video
d_video.download(SAVE_PATH)
except:
print("Some Error!")
print('Task Completed!')
我得到的错误是:
Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 1240, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1083, in request
self._send_request(method, url, body, headers)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1128, in _send_request
self.endheaders(body)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1079, in endheaders
self._send_output(message_body)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 911, in _send_output
self.send(msg)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 854, in send
self.connect()
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\http\client.py", line 1237, in connect
server_hostname=server_hostname)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 376, in wrap_socket
_context=self)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 747, in __init__
self.do_handshake()
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 983, in do_handshake
self._sslobj.do_handshake()
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\ssl.py", line 628, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:646)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "2TryingPyTube.py", line 10, in <module>
yt = YouTube(link)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\pytube\__main__.py", line 87, in __init__
self.prefetch_init()
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\pytube\__main__.py", line 95, in prefetch_init
self.prefetch()
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\pytube\__main__.py", line 158, in prefetch
self.watch_html = request.get(url=self.watch_url)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\site-packages\pytube\request.py", line 21, in get
response = urlopen(url)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 162, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 465, in open
response = self._open(req, data)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 483, in _open
'_open', req)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 443, in _call_chain
result = func(*args)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 1283, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Users\hp\AppData\Local\Programs\Python\Python35\lib\urllib\request.py", line 1242, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:646)>
我希望有人能帮助我。PS - 我只是使用 urllib、http 包的初学者。请不要写苛刻的评论,谢谢:0