I run code in Sublime Text 4 and it works.
# importing packages
from pytube import YouTube
import os
# url input from user
yt = YouTube("https://www.youtube.com/watch?v=gYmAzwQPfdY&ab_channel=TMProduction")
# extract only audio
video = yt.streams.filter(only_audio=True).first()
# check for destination to save file
destination = "/Users/am/Downloads"
# download the file
out_file = video.download(output_path=destination)
# save the file
base, ext = os.path.splitext(out_file)
new_file = base + '.mp3'
os.rename(out_file, new_file)
# result of success
print(yt.title + " has been successfully downloaded.")
I run the same code in terminal, using
python download_audio.py
and terminal gives me error messages. The last one:
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:992)>
Why is this difference occurs? Is there a way to run this script successfully from terminal?
Any help would be appreciated! Thanks!