'OSError: Could not find a suitable TLS CA certificate bundle' when using tldextract

Viewed 22

When running the program bellow, I get the error bellow. I can't figure out what the problem is, as I ran this program with no problems on my previous laptop. I was originally having problems with the pytube modue, and then I found this code which works on stackoverflow. It basically takes a list of youtube urls that are submitted and then downloads them one-by-one, if they are from the right domain (youtube).

Program:

import tldextract
from pytube import YouTube


def Download(video_list):
    for url in video_list:
        youtube = YouTube(url.strip())
        youtube.streams.get_highest_resolution().download()
        print(f'The video - {youtube.title} - was downloaded.')

video_list = []

run = True

while run == True:
    link = str(input("Enter a YouTube URL or press D to download the video(s): "))
    domain_name = tldextract.extract(link).domain
    if link.lower() == 'd':
        Download(video_list)
        run = False
    elif domain_name == 'youtube':
        video_list.append(link)
    else:
        print("Invalid youtube URL.")

Error:

Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\cache.py", line 203, in run_and_cache
    result: T = self.get(namespace=namespace, key=key_args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\cache.py", line 97, in get
    raise KeyError("namespace: " + namespace + " key: " + repr(key))
KeyError: "namespace: publicsuffix.org-tlds key: {'urls': ('https://publicsuffix.org/list/public_suffix_list.dat', 'https://raw.githubusercontent.com/publicsuffix/list/master/public_suffix_list.dat'), 'fallback_to_snapshot': True}"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\cache.py", line 203, in run_and_cache
    result: T = self.get(namespace=namespace, key=key_args)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\cache.py", line 97, in get
    raise KeyError("namespace: " + namespace + " key: " + repr(key))
KeyError: "namespace: urls key: {'url': 'https://publicsuffix.org/list/public_suffix_list.dat'}"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\User\Desktop\youtube downloader.py", line 17, in <module>
    domain_name = tldextract.extract(link).domain
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\tldextract.py", line 303, in extract
    return TLD_EXTRACTOR(url, include_psl_private_domains=include_psl_private_domains)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\tldextract.py", line 236, in __call__
    suffix_index = self._get_tld_extractor().suffix_index(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\tldextract.py", line 277, in _get_tld_extractor
    public_tlds, private_tlds = get_suffix_lists(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\suffix_list.py", line 67, in get_suffix_lists
    return cache.run_and_cache(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\cache.py", line 205, in run_and_cache
    result = func(**kwargs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\suffix_list.py", line 89, in _get_suffix_lists
    text = find_first_response(cache, urls, cache_fetch_timeout=cache_fetch_timeout)  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\suffix_list.py", line 37, in find_first_response
    return cache.cached_fetch_url(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\cache.py", line 214, in cached_fetch_url
    return self.run_and_cache(
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\cache.py", line 205, in run_and_cache
    result = func(**kwargs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\cache.py", line 223, in _fetch_url
    response = session.get(url, timeout=timeout)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 600, in get
    return self.request("GET", url, **kwargs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 460, in send
    self.cert_verify(conn, request.url, verify, cert)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\adapters.py", line 263, in cert_verify
    raise OSError(
OSError: Could not find a suitable TLS CA certificate bundle, invalid path: C:/Users/User/Downloads/BundledCertificate.cr

t

0 Answers
Related