zotify-dev / zotify

A fast and customizable music and podcast downloader.
zlib License
1.17k stars 87 forks source link

Error while downloading #48

Open Droidman007 opened 11 months ago

Droidman007 commented 11 months ago

HTTPSConnectionPool(host='audio-gm-fb.spotifycdn.com', port=443): Max retries exceeded with url: /audio/5d9238e56e52d82388d8c69a4368ea1fcc9b3ea0?Expires=1700354581~FullPath~hmac=iuWP8dynSfSurm31le1a2zDxsTixGof1h40oBjWxUBI= (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 "/data/data/com.termux/files/usr/lib/python3.11/site-packages/urllib3/connectionpool.py", line 468, in _make_request self._validate_conn(conn) File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/urllib3/connectionpool.py", line 1097, in _validate_conn conn.connect() File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/urllib3/connection.py", line 642, in connect sock_and_verified = _ssl_wrap_socket_and_match_hostname( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/urllib3/connection.py", line 783, in _ssl_wrap_socket_and_match_hostname ssl_sock = ssl_wrapsocket( ^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/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, serverhostname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/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 "/data/data/com.termux/files/usr/lib/python3.11/ssl.py", line 517, in wrap_socket return self.sslsocket_class._create( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/ssl.py", line 1108, in _create self.do_handshake() File "/data/data/com.termux/files/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 "/data/data/com.termux/files/usr/lib/python3.11/site-packages/urllib3/connectionpool.py", line 791, in urlopen response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/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 "/data/data/com.termux/files/usr/lib/python3.11/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/urllib3/connectionpool.py", line 845, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/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/5d9238e56e52d82388d8c69a4368ea1fcc9b3ea0?Expires=1700354581~FullPath~hmac=iuWP8dynSfSurm31le1a2zDxsTixGof1h40oBjWxUBI= (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 "/data/data/com.termux/files/usr/lib/python3.11/site-packages/zotify/track.py", line 224, in download_track stream = Zotify.get_content_stream(track, Zotify.DOWNLOAD_QUALITY) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/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 "/data/data/com.termux/files/usr/lib/python3.11/site-packages/librespot/audio/init.py", line 739, in load return self.load_track(playable_id, audio_quality_picker, preload, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/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 "/data/data/com.termux/files/usr/lib/python3.11/site-packages/librespot/audio/init.py", line 754, in load_stream return CdnFeedHelper.load_track(self.session, track, file, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/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 "/data/data/com.termux/files/usr/lib/python3.11/site-packages/librespot/audio/init.py", line 441, in stream_file return CdnManager.Streamer( ^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/librespot/audio/init.py", line 578, in init__ response = self.request(range_start=0, ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/librespot/audio/init.py", line 632, in request response = self.__session.client().get( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/requests/sessions.py", line 602, in get return self.request("GET", url, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/data/data/com.termux/files/usr/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/5d9238e56e52d82388d8c69a4368ea1fcc9b3ea0?Expires=1700354581~FullPath~hmac=iuWP8dynSfSurm31le1a2zDxsTixGof1h40oBjWxUBI= (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)")))

Why am I getting this error

evranch commented 11 months ago

Can confirm this issue, it's been occurring for awhile. Spotify appears to be occasionally redirecting to another server that the SSL cert is not valid for.

Simplest fix is just to run insecure SSL, and not verify signatures. Honestly, it's not like it's going to hurt anything in this case.

Unfortunately the fault appears to be upstream in librespot-python, there is a bug report and some unofficial patches can be found there if you want to build librespot yourself and tweak it. But it doesn't look feasible to set the insecure property of the session from Zotify itself, or to implement the other fix which is to not deal with audio4-gm-fb.spotifycdn.com

https://github.com/kokarare1212/librespot-python/issues/241

Edit: appears to be patched in current git version of librespot-python.

Uninstall the pip3 version of librespot-python, clone https://github.com/kokarare1212/librespot-python.git and copy/link its librespot directory into zotify's base directory.

Then run python3 -m zotify from zotify's base directory, working for me

Edit again, this is a dupe of https://github.com/zotify-dev/zotify/issues/36 that for some reason I missed