spotify-downloader: ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] on Ubuntu 18.04.1

What is the purpose of your issue?

  • Script won’t run
  • Bug
  • Feature Request
  • Question
  • Other

Description

Python Version : Python 3.6.7 Operating System : Ubuntu 18.04.1 LTS uname -a :

Linux ubuntu 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

lsb_release -a :

No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.1 LTS Release: 18.04 Codename: bionic

I’ve tried: [x] installing spotify-downloader with the pip command provided in README.md ( pip3 install spotdl ) [x] cloning the master branch and running setup.py ( python3 setup.py )

Log

imsky@ubuntu:~$ spotdl --song https://open.spotify.com/track/6USqJZjeIl6slsbStGxEgi --log-level=DEBUG
DEBUG: Fetching metadata for given track URL
DEBUG: Fetching lyrics
DEBUG: {'album': {'album_type': 'album',
               'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/7pZH7c4HbKE0ONErpw9cjP'},
                            'href': 'https://api.spotify.com/v1/artists/7pZH7c4HbKE0ONErpw9cjP',
                            'id': '7pZH7c4HbKE0ONErpw9cjP',
                            'name': 'Zámbó Jimmy',
                            'type': 'artist',
                            'uri': 'spotify:artist:7pZH7c4HbKE0ONErpw9cjP'}],
               'external_urls': {'spotify': 'https://open.spotify.com/album/48d60Coe3VuNTL3aVK1RlM'},
               'href': 'https://api.spotify.com/v1/albums/48d60Coe3VuNTL3aVK1RlM',
               'id': '48d60Coe3VuNTL3aVK1RlM',
               'images': [{'height': 640,
                           'url': 'https://i.scdn.co/image/e94f367f5d3ba10c35e80c077202e739decfa30a',
                           'width': 640},
                          {'height': 300,
                           'url': 'https://i.scdn.co/image/c4d4d75624b756169f8ff4c0de1e53828e7ec830',
                           'width': 300},
                          {'height': 64,
                           'url': 'https://i.scdn.co/image/4645eddcb5da1d2f347074c4992815940d7ce1e6',
                           'width': 64}],
               'name': 'Requiem',
               'release_date': '2014-11-01',
               'release_date_precision': 'day',
               'total_tracks': 12,
               'type': 'album',
               'uri': 'spotify:album:48d60Coe3VuNTL3aVK1RlM'},
     'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/7pZH7c4HbKE0ONErpw9cjP'},
                  'href': 'https://api.spotify.com/v1/artists/7pZH7c4HbKE0ONErpw9cjP',
                  'id': '7pZH7c4HbKE0ONErpw9cjP',
                  'name': 'Zámbó Jimmy',
                  'type': 'artist',
                  'uri': 'spotify:artist:7pZH7c4HbKE0ONErpw9cjP'}],
     'copyright': '2014 Magneoton',
     'disc_number': 1,
     'duration': 232.426,
     'explicit': False,
     'external_ids': {'isrc': 'HUMAG1400155'},
     'external_urls': {'spotify': 'https://open.spotify.com/track/6USqJZjeIl6slsbStGxEgi'},
     'genre': 'Hungarian Pop',
     'href': 'https://api.spotify.com/v1/tracks/6USqJZjeIl6slsbStGxEgi',
     'id': '6USqJZjeIl6slsbStGxEgi',
     'is_local': False,
     'lyrics': None,
     'name': 'Éjfél',
     'popularity': 11,
     'preview_url': 'https://p.scdn.co/mp3-preview/c0da593b555341d2e7bed3cde4092bceb2dba571?cid=4fe3fecfe5334023a1472516cc99d805',
     'publisher': 'Magneoton',
     'release_date': '2014-11-01',
     'total_tracks': 12,
     'track_number': 1,
     'type': 'track',
     'uri': 'spotify:track:6USqJZjeIl6slsbStGxEgi',
     'year': '2014'}
DEBUG: Opening URL: https://www.youtube.com/results?sp=EgIQAQ%253D%253D&q=Z%C3%A1mb%C3%B3%20Jimmy%20-%20%C3%89jf%C3%A9l%20lyrics
Traceback (most recent call last):
  File "/usr/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/usr/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/usr/lib/python3.6/http/client.py", line 1400, in connect
    server_hostname=server_hostname)
  File "/usr/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/usr/lib/python3.6/ssl.py", line 817, in __init__
    self.do_handshake()
  File "/usr/lib/python3.6/ssl.py", line 1077, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/imsky/.local/bin/spotdl", line 11, in <module>
    sys.exit(main())
  File "/home/imsky/.local/lib/python3.6/site-packages/spotdl/spotdl.py", line 62, in main
    match_args()
  File "/home/imsky/.local/lib/python3.6/site-packages/spotdl/spotdl.py", line 27, in match_args
    track_dl = downloader.Downloader(raw_song=track)
  File "/home/imsky/.local/lib/python3.6/site-packages/spotdl/downloader.py", line 93, in __init__
    self.content, self.meta_tags = youtube_tools.match_video_and_metadata(raw_song)
  File "/home/imsky/.local/lib/python3.6/site-packages/spotdl/youtube_tools.py", line 58, in match_video_and_metadata
    content = go_pafy(track, meta_tags)
  File "/home/imsky/.local/lib/python3.6/site-packages/spotdl/youtube_tools.py", line 32, in go_pafy
    track_url = generate_youtube_url(raw_song, meta_tags)
  File "/home/imsky/.local/lib/python3.6/site-packages/spotdl/youtube_tools.py", line 160, in generate_youtube_url
    url = url_fetch.scrape()
  File "/home/imsky/.local/lib/python3.6/site-packages/spotdl/youtube_tools.py", line 254, in scrape
    item = self._fetch_response(search_url).read()
  File "/home/imsky/.local/lib/python3.6/site-packages/spotdl/youtube_tools.py", line 340, in _fetch_response
    return urllib.request.urlopen(url)
  File "/usr/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/usr/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/usr/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/usr/lib/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)>

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (7 by maintainers)

Most upvoted comments

I had a similar problem on one of my Linux machines. Generating fresh certificates and exporting an environment variable pointing to the certificates directory fixed it:

$ sudo update-ca-certificates --fresh
$ export SSL_CERT_DIR=/etc/ssl/certs

Was getting same error from Python 3.6.8 on Ubuntu 16.04.6 LTS and @ritiek solution worked for me!

$ sudo update-ca-certificates --fresh $ export SSL_CERT_DIR=/etc/ssl/certs

On MacOS 11.14 with Python 3.6.4 running the following fixed it for me:

$ pip3 install certifi
$ /Applications/Python\ 3.6/Install\ Certificates.command

Thanks the below solution did work for me

$ sudo update-ca-certificates --fresh $ export SSL_CERT_DIR=/etc/ssl/certs

When you are using a self signed cert urllib3 version 1.25.3 refuses to ignore the SSL cert

To fix remove urllib3-1.25.3 and install urllib3-1.24.3

pip3 uninstall urllib3

pip3 install urllib3==1.24.3

Tested on Linux MacOS and Window$

@CarterKwon If by any chance you’re on OSX, there is a similar issue #125.

As for Linux, I’d like to know whether this code works on python 3 without resulting in an error:

import urllib.request
urllib.request.urlopen("https://google.com/")

and what about trying to fetch the same YouTube search result page that failed (as in log):

import urllib.request
urllib.request.urlopen("https://www.youtube.com/results?sp=EgIQAQ%253D%253D&q=Z%C3%A1mb%C3%B3%20Jimmy%20-%20%C3%89jf%C3%A9l%20lyrics")

Also, are you able to open that URL: https://www.youtube.com/results?sp=EgIQAQ%253D%253D&q=Zámbó Jimmy - Éjfél lyrics in the web browser?

This might also be of some help: https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error