zotify-dev / zotify

A fast and customizable music and podcast downloader.
zlib License
1.04k stars 79 forks source link

SSL Certificate issue. #36

Open Bwall95 opened 11 months ago

Bwall95 commented 11 months ago

getting the following when downloading music. Appears randomly. Some songs download , some don't. If I retry it enough times it eventually works? Just extremely annoying. Issue:

HTTPSConnectionPool(host='audio4-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/3d90279a75e9c37be75fc75989e4ef9257590efb?Expires=1698359610~FullPath~hmac=YjbTTh1pW5ZoLsCN1SqAZvgG8ZqMzs4UZuuzK2UWLAA= (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio4-gm-fb.spotifycdn.com'. (_ssl.c:1000)")))

Traceback (most recent call last): File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\urllib3\connectionpool.py", line 468, in _make_request self._validate_conn(conn) File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\urllib3\connectionpool.py", line 1097, in _validate_conn conn.connect() File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\urllib3\connection.py", line 642, in connect sock_and_verified = _ssl_wrap_socket_and_match_hostname( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\urllib3\connection.py", line 783, in _ssl_wrap_socket_and_match_hostname ssl_sock = ssl_wrapsocket( ^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\urllib3\util\ssl.py", line 471, in ssl_wrap_socket ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, serverhostname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\urllib3\util\ssl.py", line 515, in _ssl_wrap_socket_impl return ssl_context.wrap_socket(sock, server_hostname=server_hostname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\ssl.py", line 455, in wrap_socket return self.sslsocket_class._create( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\ssl.py", line 1046, in _create self.do_handshake() File "C:\Users\Bwall\scoop\apps\python\current\Lib\ssl.py", line 1317, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio4-gm-fb.spotifycdn.com'. (_ssl.c:1000)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\urllib3\connectionpool.py", line 791, in urlopen response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\urllib3\connectionpool.py", line 492, in _make_request raise new_e urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio4-gm-fb.spotifycdn.com'. (_ssl.c:1000)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\requests\adapters.py", line 486, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\urllib3\connectionpool.py", line 845, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\urllib3\util\retry.py", line 515, in increment raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='audio4-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/3d90279a75e9c37be75fc75989e4ef9257590efb?Expires=1698359610~FullPath~hmac=YjbTTh1pW5ZoLsCN1SqAZvgG8ZqMzs4UZuuzK2UWLAA= (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio4-gm-fb.spotifycdn.com'. (_ssl.c:1000)")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\zotify\track.py", line 224, in download_track stream = Zotify.get_content_stream(track, Zotify.DOWNLOAD_QUALITY) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\zotify\zotify.py", line 53, in get_content_stream return cls.SESSION.content_feeder().load(content_id, VorbisOnlyAudioQuality(quality), False, None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\librespot\audio__init.py", line 736, in load return self.load_track(playable_id, audio_quality_picker, preload, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\librespot\audio__init.py", line 797, in load_track return self.load_stream(file, track, None, preload, halt_listener) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\librespot\audio__init.py", line 751, in load_stream return CdnFeedHelper.load_track(self.session, track, file, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\librespot\audio__init__.py", line 339, in load_track streamer = session.cdn().stream_file(file, key, url, halt_listener) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\librespot\audio__init__.py", line 438, in stream_file return CdnManager.Streamer( ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\librespot\audio\init.py", line 575, in init__ response = self.request(range_start=0, ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\librespot\audio\init.py", line 629, in request response = self.session.client().get( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\requests\sessions.py", line 602, in get return self.request("GET", url, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\requests\sessions.py", line 589, in request resp = self.send(prep, send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\requests\sessions.py", line 703, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bwall\scoop\apps\python\current\Lib\site-packages\requests\adapters.py", line 517, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='audio4-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/3d90279a75e9c37be75fc75989e4ef9257590efb?Expires=1698359610~FullPath~hmac=YjbTTh1pW5ZoLsCN1SqAZvgG8ZqMzs4UZuuzK2UWLAA= (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio4-gm-fb.spotifycdn.com'. (_ssl.c:1000)")))

Blue5876 commented 11 months ago

I'm getting this same error. It seems to happen randomly. For the time being, just keep attempting to redownload the album/playlist with the skip already existing config option on, and eventually you'll get them all.

xerootg commented 10 months ago

there's a sort-of fix in this commit which i patched into my install on my box. probably a bad idea to go patch an installed library, but yolo.

Red6785 commented 10 months ago

I'd be lying if I said I knew how to do that.. I'll find out eventually, though. Thanks!

Blue5876 commented 10 months ago

I got it, but it didn't seem to fix anything for me.

xerootg commented 10 months ago

I got it, but it didn't seem to fix anything for me.

do you still see audio4-gm-fb.spotifycdn.com in the exception? if so, then you might have missed something. the ssl error follows an exception about attempting to extract the expiration token, due to \~FullPath\~ in the parameters immediately after the expiration.

Red6785 commented 10 months ago

Yeah, same error. Would it work to just download that file from the github you linked and slap that in there instead of attempting to just patch the code manually?

xerootg commented 10 months ago

well, I'm only occasionally a python dev, so i don't know for sure, but you might be able to use pip to manually install that repo, with that fix and all. if you do choose to download that whole file and replace it, make a backup. are you sure you edited the correct version of librespot, as in the version zotify uses? like i said, making this change like this is sketch, but it does show that the upstream dependency is aware of the issue.

Notice that this project uses a non-mainline version of librespot

Blue5876 commented 10 months ago

I edited the wrong one, oops. I got it now and it works fine, thanks!

hicsuntdragons commented 10 months ago

So, I had this problem, and updated zotify via pipx today, and the patch is already applied. But the problem still happens...

zotify-dev commented 10 months ago

So, I had this problem, and updated zotify via pipx today, and the patch is already applied. But the problem still happens...

Could you please provide a traceback?

hicsuntdragons commented 10 months ago

So, I had this problem, and updated zotify via pipx today, and the patch is already applied. But the problem still happens...

Could you please provide a traceback?

sure! took me a while to use this again. paste here, raw bellow. zot_down is an alias to

zotify --root-path ~/resources_media/music\ albuns/zotify --download-real-time true --output "{artist}/[{release_year}] {album}/{album_num} {song_name}.{ext}" --skip-existing true $1

and, as I said, suggested patch on commit is aplied on ~/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py, line 322-326 (just in case this is the wrong spot)

zot_down 'https://open.spotify.com/album/0EevA0t8Qcxh4TFLtBQPyo?si=43851a5e211d4266'
    [∙●∙] Preparing download... ###   SKIPPING: Voivod - Le Pont Noir (GENERAL DOWNLOAD ERROR)   ###
Track_ID: 5uyfwPcP7HrmLR1oxNOayo
album_num: 03
artist: Voivod
album: The Outer Limits
album_id: 0EevA0t8Qcxh4TFLtBQPyo

HTTPSConnectionPool(host='audio-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/ca530fd718c3f20c2de1290dea3d5a9c0bbd5362?Expires=1699116140~FullPath~hmac=rwuVBEUG-LbiZ65VdyQCjA164u-AjOICHpiA0LlDOho= (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)")))

    [∙∙●] Preparing download... Traceback (most recent call last):
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 468, in _make_request
    self._validate_conn(conn)
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1097, in _validate_conn
    conn.connect()
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connection.py", line 642, in connect
    sock_and_verified = _ssl_wrap_socket_and_match_hostname(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connection.py", line 783, in _ssl_wrap_socket_and_match_hostname
    ssl_sock = ssl_wrap_socket(
               ^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/util/ssl_.py", line 471, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/util/ssl_.py", line 515, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ssl.py", line 517, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ssl.py", line 1108, in _create
    self.do_handshake()
  File "/usr/lib/python3.11/ssl.py", line 1379, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 791, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 492, in _make_request
    raise new_e
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 845, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='audio-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/ca530fd718c3f20c2de1290dea3d5a9c0bbd5362?Expires=1699116140~FullPath~hmac=rwuVBEUG-LbiZ65VdyQCjA164u-AjOICHpiA0LlDOho= (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/zotify/track.py", line 224, in download_track
    stream = Zotify.get_content_stream(track, Zotify.DOWNLOAD_QUALITY)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/zotify/zotify.py", line 53, in get_content_stream
    return cls.SESSION.content_feeder().load(content_id, VorbisOnlyAudioQuality(quality), False, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 739, in load
    return self.load_track(playable_id, audio_quality_picker, preload,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 800, in load_track
    return self.load_stream(file, track, None, preload, halt_listener)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 754, in load_stream
    return CdnFeedHelper.load_track(self.__session, track, file,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 342, in load_track
    streamer = session.cdn().stream_file(file, key, url, halt_listener)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 441, in stream_file
    return CdnManager.Streamer(
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 578, in __init__
    response = self.request(range_start=0,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 632, in request
    response = self.__session.client().get(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/adapters.py", line 517, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='audio-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/ca530fd718c3f20c2de1290dea3d5a9c0bbd5362?Expires=1699116140~FullPath~hmac=rwuVBEUG-LbiZ65VdyQCjA164u-AjOICHpiA0LlDOho= (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)")))

    [∙∙●] Preparing download... ###   SKIPPING: Voivod - Jack Luminous (GENERAL DOWNLOAD ERROR)   ###
Track_ID: 6squLDyXKXZRgcJ8sjC0XG
album_num: 07
artist: Voivod
album: The Outer Limits
album_id: 0EevA0t8Qcxh4TFLtBQPyo

HTTPSConnectionPool(host='audio-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/91073a48a639cf5ff7503dc36d9bb4346fd50330?Expires=1699116976~FullPath~hmac=3jx1oSVLEUIq9W5te130O-7Xmco6uxy-qNvlrN2_wU8= (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)")))

Traceback (most recent call last):
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 468, in _make_request
    self._validate_conn(conn)
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1097, in _validate_conn
    conn.connect()
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connection.py", line 642, in connect
    sock_and_verified = _ssl_wrap_socket_and_match_hostname(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connection.py", line 783, in _ssl_wrap_socket_and_match_hostname
    ssl_sock = ssl_wrap_socket(
               ^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/util/ssl_.py", line 471, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/util/ssl_.py", line 515, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ssl.py", line 517, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ssl.py", line 1108, in _create
    self.do_handshake()
  File "/usr/lib/python3.11/ssl.py", line 1379, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 791, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 492, in _make_request
    raise new_e
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 845, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='audio-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/91073a48a639cf5ff7503dc36d9bb4346fd50330?Expires=1699116976~FullPath~hmac=3jx1oSVLEUIq9W5te130O-7Xmco6uxy-qNvlrN2_wU8= (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/zotify/track.py", line 224, in download_track
    stream = Zotify.get_content_stream(track, Zotify.DOWNLOAD_QUALITY)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/zotify/zotify.py", line 53, in get_content_stream
    return cls.SESSION.content_feeder().load(content_id, VorbisOnlyAudioQuality(quality), False, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 739, in load
    return self.load_track(playable_id, audio_quality_picker, preload,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 800, in load_track
    return self.load_stream(file, track, None, preload, halt_listener)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 754, in load_stream
    return CdnFeedHelper.load_track(self.__session, track, file,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 342, in load_track
    streamer = session.cdn().stream_file(file, key, url, halt_listener)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 441, in stream_file
    return CdnManager.Streamer(
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 578, in __init__
    response = self.request(range_start=0,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 632, in request
    response = self.__session.client().get(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/adapters.py", line 517, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='audio-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/91073a48a639cf5ff7503dc36d9bb4346fd50330?Expires=1699116976~FullPath~hmac=3jx1oSVLEUIq9W5te130O-7Xmco6uxy-qNvlrN2_wU8= (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)")))

    [∙●∙] Preparing download... ###   SKIPPING: Voivod - Wrong-Way Street (GENERAL DOWNLOAD ERROR)   ###
Track_ID: 1hyxnGkjpX6b1c8O2jSrBp
album_num: 08
artist: Voivod
album: The Outer Limits
album_id: 0EevA0t8Qcxh4TFLtBQPyo

HTTPSConnectionPool(host='audio-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/a60e8bb86a8bf7d0ab76b26b0877ea219183d22a?Expires=1699116978~FullPath~hmac=WtJrkCbj0mYu5MD03lj9zb3ZCmiLltt8XrT230Ranc8= (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)")))

Traceback (most recent call last):
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 468, in _make_request
    self._validate_conn(conn)
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1097, in _validate_conn
    conn.connect()
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connection.py", line 642, in connect
    sock_and_verified = _ssl_wrap_socket_and_match_hostname(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connection.py", line 783, in _ssl_wrap_socket_and_match_hostname
    ssl_sock = ssl_wrap_socket(
               ^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/util/ssl_.py", line 471, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/util/ssl_.py", line 515, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ssl.py", line 517, in wrap_socket
    return self.sslsocket_class._create(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ssl.py", line 1108, in _create
    self.do_handshake()
  File "/usr/lib/python3.11/ssl.py", line 1379, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 791, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 492, in _make_request
    raise new_e
urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/connectionpool.py", line 845, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='audio-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/a60e8bb86a8bf7d0ab76b26b0877ea219183d22a?Expires=1699116978~FullPath~hmac=WtJrkCbj0mYu5MD03lj9zb3ZCmiLltt8XrT230Ranc8= (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/zotify/track.py", line 224, in download_track
    stream = Zotify.get_content_stream(track, Zotify.DOWNLOAD_QUALITY)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/zotify/zotify.py", line 53, in get_content_stream
    return cls.SESSION.content_feeder().load(content_id, VorbisOnlyAudioQuality(quality), False, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 739, in load
    return self.load_track(playable_id, audio_quality_picker, preload,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 800, in load_track
    return self.load_stream(file, track, None, preload, halt_listener)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 754, in load_stream
    return CdnFeedHelper.load_track(self.__session, track, file,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 342, in load_track
    streamer = session.cdn().stream_file(file, key, url, halt_listener)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 441, in stream_file
    return CdnManager.Streamer(
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 578, in __init__
    response = self.request(range_start=0,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/librespot/audio/__init__.py", line 632, in request
    response = self.__session.client().get(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/juliac/.local/pipx/venvs/zotify/lib/python3.11/site-packages/requests/adapters.py", line 517, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='audio-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/a60e8bb86a8bf7d0ab76b26b0877ea219183d22a?Expires=1699116978~FullPath~hmac=WtJrkCbj0mYu5MD03lj9zb3ZCmiLltt8XrT230Ranc8= (Caused by SSLError(SSLCertVerificationError(1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: Hostname mismatch, certificate is not valid for 'audio-gm-fb.spotifycdn.com'. (_ssl.c:1006)")))

100%|███████████████████████████████████████████████████████████| 9.00/9.00 [27:42<00:00, 185s/Song]
byrongamatos commented 10 months ago

@xerootg solution worked great for me, the SSL errors are gone, i can now download albums in one go

liamharper2453 commented 10 months ago

@hicsuntdragons Current fix for this is modifying C:\Users{username}.local\pipx\venvs\zotify\Lib\site-packages\librespot\audio__init__.py and at line 322 use this method:

    @staticmethod
    def get_url(resp: StorageResolve.StorageResolveResponse) -> str:
        selected_url = random.choice(resp.cdnurl)
        while "audio4-gm-fb" in selected_url:
            selected_url = random.choice(resp.cdnurl)
        while "audio-gm-fb" in selected_url:
            selected_url = random.choice(resp.cdnurl)
        return selected_url

Basically, also adding the exclusion for 'audio-gm-fb' (latest version of librespot already has the exclusion for 'audio4-gm-fb').

luphoria commented 10 months ago

why not simply trust the expired certificate?

liamharper2453 commented 10 months ago

why not simply trust the expired certificate?

It's not expired. It seems to be misconfigured. The hostname on the certificate (audio-gm-off.spotifycdn.com) doesn't match the hostname of the CDN domain it has been installed on (audio-gm-fb.spotifycdn.com).

liamharper2453 commented 10 months ago

@hicsuntdragons Current fix for this is modifying C:\Users{username}.local\pipx\venvs\zotify\Lib\site-packages\librespot\audioinit.py and at line 322 use this method:

    @staticmethod
    def get_url(resp: StorageResolve.StorageResolveResponse) -> str:
        selected_url = random.choice(resp.cdnurl)
        while "audio4-gm-fb" in selected_url:
            selected_url = random.choice(resp.cdnurl)
        while "audio-gm-fb" in selected_url:
            selected_url = random.choice(resp.cdnurl)
        return selected_url

Basically, also adding the exclusion for 'audio-gm-fb' (latest version of librespot already has the exclusion for 'audio4-gm-fb').

I have now merged the exclusion upstream. If you re-install zotify this should now be resolved and you shouldn't need to manually apply this exclusion.

hicsuntdragons commented 10 months ago

tested with three links, working for me. Thanks!

byrongamatos commented 10 months ago

I can also confirm the issue is gone after the update. Thank you

Bwall95 commented 10 months ago

@hicsuntdragons Current fix for this is modifying C:\Users{username}.local\pipx\venvs\zotify\Lib\site-packages\librespot\audioinit.py and at line 322 use this method:

    @staticmethod
    def get_url(resp: StorageResolve.StorageResolveResponse) -> str:
        selected_url = random.choice(resp.cdnurl)
        while "audio4-gm-fb" in selected_url:
            selected_url = random.choice(resp.cdnurl)
        while "audio-gm-fb" in selected_url:
            selected_url = random.choice(resp.cdnurl)
        return selected_url

Basically, also adding the exclusion for 'audio-gm-fb' (latest version of librespot already has the exclusion for 'audio4-gm-fb').

I have now merged the exclusion upstream. If you re-install zotify this should now be resolved and you shouldn't need to manually apply this exclusion.

Worked for me! Thanks!

evranch commented 10 months ago

The reinstall didn't work for me, but pip is a little borked on the old relic I use for downloading media.

However I did manage to get it to work by cloning the latest version of librespot-python, and running zotify directly with python3 -m zotify