spotify-downloader: Running the commands to donwload user saved albums or songs fails with error 'ResponseError: too many 429 error responses'

System OS

Windows

Python Version

3.10 (CPython)

Install Source

pip / PyPi

Install version / commit hash

v4.2.5

Expected Behavior vs Actual Behavior

Trying to download the user saved albums or song throws this error

Max Retries reached

An error occurred
ResponseError: too many 429 error responses

Steps to reproduce - Ensure to include actual links!

python -m spotdl download all-user-saved-albums --user-auth

Traceback

python -m spotdl download all-user-saved-albums --user-auth
Processing query: all-user-saved-albums
Max Retries reached

An error occurred
ResponseError: too many 429 error responses

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

╭─────────────────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────────────────╮
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\requests\adapters.py:667 in send                                                                                                    │
│                                                                                                                                         │
│   664 │   │   │   timeout = TimeoutSauce(connect=timeout, read=timeout)                                                                 │
│   665 │   │                                                                                                                             │
│   666 │   │   try:                                                                                                                      │
│ ❱ 667 │   │   │   resp = conn.urlopen(                                                                                                  │
│   668 │   │   │   │   method=request.method,                                                                                            │
│   669 │   │   │   │   url=url,                                                                                                          │
│   670 │   │   │   │   body=request.body,                                                                                                │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\urllib3\connectionpool.py:948 in urlopen                                                                                            │
│                                                                                                                                         │
│    945 │   │   │   response.drain_conn()                                                                                                │
│    946 │   │   │   retries.sleep(response)                                                                                              │
│    947 │   │   │   log.debug("Retry: %s", url)                                                                                          │
│ ❱  948 │   │   │   return self.urlopen(                                                                                                 │
│    949 │   │   │   │   method,                                                                                                          │
│    950 │   │   │   │   url,                                                                                                             │
│    951 │   │   │   │   body,                                                                                                            │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\urllib3\connectionpool.py:948 in urlopen                                                                                            │
│                                                                                                                                         │
│    945 │   │   │   response.drain_conn()                                                                                                │
│    946 │   │   │   retries.sleep(response)                                                                                              │
│    947 │   │   │   log.debug("Retry: %s", url)                                                                                          │
│ ❱  948 │   │   │   return self.urlopen(                                                                                                 │
│    949 │   │   │   │   method,                                                                                                          │
│    950 │   │   │   │   url,                                                                                                             │
│    951 │   │   │   │   body,                                                                                                            │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\urllib3\connectionpool.py:948 in urlopen                                                                                            │
│                                                                                                                                         │
│    945 │   │   │   response.drain_conn()                                                                                                │
│    946 │   │   │   retries.sleep(response)                                                                                              │
│    947 │   │   │   log.debug("Retry: %s", url)                                                                                          │
│ ❱  948 │   │   │   return self.urlopen(                                                                                                 │
│    949 │   │   │   │   method,                                                                                                          │
│    950 │   │   │   │   url,                                                                                                             │
│    951 │   │   │   │   body,                                                                                                            │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\urllib3\connectionpool.py:938 in urlopen                                                                                            │
│                                                                                                                                         │
│    935 │   │   has_retry_after = bool(response.headers.get("Retry-After"))                                                              │
│    936 │   │   if retries.is_retry(method, response.status, has_retry_after):                                                           │
│    937 │   │   │   try:                                                                                                                 │
│ ❱  938 │   │   │   │   retries = retries.increment(method, url, response=response, _pool=self)                                          │
│    939 │   │   │   except MaxRetryError:                                                                                                │
│    940 │   │   │   │   if retries.raise_on_status:                                                                                      │
│    941 │   │   │   │   │   response.drain_conn()                                                                                        │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\urllib3\util\retry.py:515 in increment                                                                                              │
│                                                                                                                                         │
│   512 │   │                                                                                                                             │
│   513 │   │   if new_retry.is_exhausted():                                                                                              │
│   514 │   │   │   reason = error or ResponseError(cause)                                                                                │
│ ❱ 515 │   │   │   raise MaxRetryError(_pool, url, reason) from reason  # type:                                                          │
│       ignore[arg-type]                                                                                                                  │
│   516 │   │                                                                                                                             │
│   517 │   │   log.debug("Incremented Retry for (url='%s'): %r", url, new_retry)                                                         │
│   518                                                                                                                                   │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
MaxRetryError: HTTPSConnectionPool(host='api.spotify.com', port=443): Max retries exceeded with url: /v1/albums/6V4QJ3nyhgFiMGGPH7VupN
(Caused by ResponseError('too many 429 error responses'))

During handling of the above exception, another exception occurred:

╭─────────────────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────────────────╮
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\spotipy\client.py:270 in _internal_call                                                                                             │
│                                                                                                                                         │
│    267 │   │   │   │   │    method, url, args.get("params"), headers, args.get('data'))                                                 │
│    268 │   │                                                                                                                            │
│    269 │   │   try:                                                                                                                     │
│ ❱  270 │   │   │   response = self._session.request(                                                                                    │
│    271 │   │   │   │   method, url, headers=headers, proxies=self.proxies,                                                              │
│    272 │   │   │   │   timeout=self.requests_timeout, **args                                                                            │
│    273 │   │   │   )                                                                                                                    │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\requests\sessions.py:589 in request                                                                                                 │
│                                                                                                                                         │
│   586 │   │   │   "allow_redirects": allow_redirects,                                                                                   │
│   587 │   │   }                                                                                                                         │
│   588 │   │   send_kwargs.update(settings)                                                                                              │
│ ❱ 589 │   │   resp = self.send(prep, **send_kwargs)                                                                                     │
│   590 │   │                                                                                                                             │
│   591 │   │   return resp                                                                                                               │
│   592                                                                                                                                   │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\requests\sessions.py:703 in send                                                                                                    │
│                                                                                                                                         │
│   700 │   │   start = preferred_clock()                                                                                                 │
│   701 │   │                                                                                                                             │
│   702 │   │   # Send the request                                                                                                        │
│ ❱ 703 │   │   r = adapter.send(request, **kwargs)                                                                                       │
│   704 │   │                                                                                                                             │
│   705 │   │   # Total elapsed time of the request (approximately)                                                                       │
│   706 │   │   elapsed = preferred_clock() - start                                                                                       │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\requests\adapters.py:691 in send                                                                                                    │
│                                                                                                                                         │
│   688 │   │   │   │   │   raise ConnectTimeout(e, request=request)                                                                      │
│   689 │   │   │                                                                                                                         │
│   690 │   │   │   if isinstance(e.reason, ResponseError):                                                                               │
│ ❱ 691 │   │   │   │   raise RetryError(e, request=request)                                                                              │
│   692 │   │   │                                                                                                                         │
│   693 │   │   │   if isinstance(e.reason, _ProxyError):                                                                                 │
│   694 │   │   │   │   raise ProxyError(e, request=request)                                                                              │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
RetryError: HTTPSConnectionPool(host='api.spotify.com', port=443): Max retries exceeded with url: /v1/albums/6V4QJ3nyhgFiMGGPH7VupN (Caused
by ResponseError('too many 429 error responses'))

During handling of the above exception, another exception occurred:

╭─────────────────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────────────────╮
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\spotdl\console\entry_point.py:142 in console_entry_point                                                                            │
│                                                                                                                                         │
│   139 │   try:                                                                                                                          │
│   140 │   │   # Pick the operation to perform                                                                                           │
│   141 │   │   # based on the name and run it!                                                                                           │
│ ❱ 142 │   │   OPERATIONS[arguments.operation](                                                                                          │
│   143 │   │   │   query=arguments.query,                                                                                                │
│   144 │   │   │   downloader=downloader,                                                                                                │
│   145 │   │   )                                                                                                                         │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\spotdl\console\download.py:25 in download                                                                                           │
│                                                                                                                                         │
│   22 │   """                                                                                                                            │
│   23 │                                                                                                                                  │
│   24 │   # Parse the query                                                                                                              │
│ ❱ 25 │   songs = get_simple_songs(                                                                                                      │
│   26 │   │   query,                                                                                                                     │
│   27 │   │   use_ytm_data=downloader.settings["ytm_data"],                                                                              │
│   28 │   │   playlist_numbering=downloader.settings["playlist_numbering"],                                                              │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\spotdl\utils\search.py:280 in get_simple_songs                                                                                      │
│                                                                                                                                         │
│   277 │   │   elif request == "all-user-followed-artists":                                                                              │
│   278 │   │   │   lists.extend(get_user_followed_artists())                                                                             │
│   279 │   │   elif request == "all-user-saved-albums":                                                                                  │
│ ❱ 280 │   │   │   lists.extend(get_user_saved_albums())                                                                                 │
│   281 │   │   elif request == "all-saved-playlists":                                                                                    │
│   282 │   │   │   lists.extend(get_all_saved_playlists())                                                                               │
│   283 │   │   elif request.endswith(".spotdl"):                                                                                         │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\spotdl\utils\search.py:443 in get_user_saved_albums                                                                                 │
│                                                                                                                                         │
│   440 │   │   user_saved_albums_response = response                                                                                     │
│   441 │   │   user_saved_albums.extend(user_saved_albums_response["items"])                                                             │
│   442 │                                                                                                                                 │
│ ❱ 443 │   return [                                                                                                                      │
│   444 │   │   Album.from_url(item["album"]["external_urls"]["spotify"], fetch_songs=False)                                              │
│   445 │   │   for item in user_saved_albums                                                                                             │
│   446 │   ]                                                                                                                             │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\spotdl\utils\search.py:444 in <listcomp>                                                                                            │
│                                                                                                                                         │
│   441 │   │   user_saved_albums.extend(user_saved_albums_response["items"])                                                             │
│   442 │                                                                                                                                 │
│   443 │   return [                                                                                                                      │
│ ❱ 444 │   │   Album.from_url(item["album"]["external_urls"]["spotify"], fetch_songs=False)                                              │
│   445 │   │   for item in user_saved_albums                                                                                             │
│   446 │   ]                                                                                                                             │
│   447                                                                                                                                   │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\spotdl\types\song.py:306 in from_url                                                                                                │
│                                                                                                                                         │
│   303 │   │   - The SongList object.                                                                                                    │
│   304 │   │   """                                                                                                                       │
│   305 │   │                                                                                                                             │
│ ❱ 306 │   │   metadata, songs = cls.get_metadata(url)                                                                                   │
│   307 │   │   urls = [song.url for song in songs]                                                                                       │
│   308 │   │                                                                                                                             │
│   309 │   │   if fetch_songs:                                                                                                           │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\spotdl\types\album.py:42 in get_metadata                                                                                            │
│                                                                                                                                         │
│    39 │   │                                                                                                                             │
│    40 │   │   spotify_client = SpotifyClient()                                                                                          │
│    41 │   │                                                                                                                             │
│ ❱  42 │   │   album_metadata = spotify_client.album(url)                                                                                │
│    43 │   │   if album_metadata is None:                                                                                                │
│    44 │   │   │   raise AlbumError(                                                                                                     │
│    45 │   │   │   │   "Couldn't get metadata, check if you have passed correct album id"                                                │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\spotipy\client.py:476 in album                                                                                                      │
│                                                                                                                                         │
│    473 │   │   if market is not None:                                                                                                   │
│    474 │   │   │   return self._get("albums/" + trid + '?market=' + market)                                                             │
│    475 │   │   else:                                                                                                                    │
│ ❱  476 │   │   │   return self._get("albums/" + trid)                                                                                   │
│    477 │                                                                                                                                │
│    478 │   def album_tracks(self, album_id, limit=50, offset=0, market=None):                                                           │
│    479 │   │   """ Get Spotify catalog information about an album's tracks                                                              │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\spotdl\utils\spotify.py:195 in _get                                                                                                 │
│                                                                                                                                         │
│   192 │   │   retries = self.max_retries  # type: ignore # pylint: disable=E1101                                                        │
│   193 │   │   while response is None:                                                                                                   │
│   194 │   │   │   try:                                                                                                                  │
│ ❱ 195 │   │   │   │   response = self._internal_call("GET", url, payload, kwargs)                                                       │
│   196 │   │   │   except (requests.exceptions.Timeout, requests.ConnectionError) as exc:                                                │
│   197 │   │   │   │   retries -= 1                                                                                                      │
│   198 │   │   │   │   if retries <= 0:                                                                                                  │
│                                                                                                                                         │
│ C:\Users\yayit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packa │
│ ges\spotipy\client.py:311 in _internal_call                                                                                             │
│                                                                                                                                         │
│    308 │   │   │   │   reason = retry_error.args[0].reason                                                                              │
│    309 │   │   │   except (IndexError, AttributeError):                                                                                 │
│    310 │   │   │   │   reason = None                                                                                                    │
│ ❱  311 │   │   │   raise SpotifyException(                                                                                              │
│    312 │   │   │   │   429,                                                                                                             │
│    313 │   │   │   │   -1,                                                                                                              │
│    314 │   │   │   │   f"{request.path_url}:\n Max Retries",                                                                            │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
SpotifyException: http status: 429, code:-1 - /v1/albums/6V4QJ3nyhgFiMGGPH7VupN:
 Max Retries, reason: too many 429 error responses

Other details

I get same error with playlist with more than 400 songs.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 22 (5 by maintainers)

Most upvoted comments

By default spotDL uses a preconfigured Spotify app thats the same for all users (so many users using spotDL at the same time will lead to the rate limit being exceeded). You can bypass this by creating your own app at https://developer.spotify.com/dashboard , for the name and description enter whatever you like, redirect URI http://127.0.0.1:9900/ and select Web API at the bottom. Then enter the client ID and client secret in the spotdl config.json.

Edit: you’ll also need to delete the .spotipy file and relogin with your newly created app

@sagivoulu you might want to think about your approach towards the metadata-cache-ttl; if all metadata expires at the same time, you will hit the rate limits once again.

Alternatively, you might want to implement respecting the Spotify ratelimits (using the Retry-After header, see https://developer.spotify.com/documentation/web-api/concepts/rate-limits). You could then sleep for that amount of time (and maybe tell the user that they will hit less rate limits if they add their own API keys.

FYI just adding those two options with my own Spotify app details worked:

dl-spotify:
    image: spotdl/spotify-downloader:latest
    volumes:
        - xxxx:/music
    command: download https://open.spotify.com/xxxx --output "{album}/{title}.{output-ext}" --client-id xxx --client-secret xxx

It’s not even just user saved albums or songs, it fails if you try to download a playlist or all songs of an artist using the spotify link

Still having same error with spotdl download saved --user-auth, spotdl download all-user-playlists --user-auth and spotdl download all-user-saved-albums --user-auth