spotDL / spotify-downloader

Download your Spotify playlists and songs along with album art and metadata (from YouTube if a match is found).
https://spotdl.readthedocs.io/en/latest/
MIT License
17.8k stars 1.62k forks source link

SpotifyException HTTP404 Error, HTTP Error for GET - Cannot download songs #1497

Closed domlysi closed 2 years ago

domlysi commented 2 years ago

System Operating System (OS)

Linux

Python Version

3.8 (CPython)

Install Source

GitHub

Install version / commit hash

3.9.4

Expected Behavior vs Actual Behavior

I was trying to download a playlist containing a bigger amount of songs. I noticed that while fetching the names and looking them up on YouTube, I got random HTTP 404 on requests going to Spotify. With every run, it randomly appears on songs, that definitely exist (I checked the URL manually).

I'm guessing, that there is a rate limit or something similar on Spotify's end.

My suggestion - that I also already tested locally - would be to retry the failed requests instead of exiting out and to continue downloading the rest instead of just failing.

Steps to reproduce

  1. Try to download a huge playlist

Traceback

Traceback (most recent call last):
  File "/**/venv/lib/python3.8/site-packages/spotipy/client.py", line 245, in _internal_call
    response.raise_for_status()
  File "/**/venv/lib/python3.8/site-packages/requests/models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.spotify.com/v1/tracks/22ea9e9wspXjaR7qfqfsdS

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/**/venv/bin/spotdl", line 8, in <module>
    sys.exit(console_entry_point())
  File "/**/venv/lib/python3.8/site-packages/spotdl/console/__init__.py", line 78, in console_entry_point
    song_list = parse_query(
  File "/**/venv/lib/python3.8/site-packages/spotdl/parsers/query_parser.py", line 29, in parse_query
    parse_request(
  File "/**/venv/lib/python3.8/site-packages/spotdl/parsers/query_parser.py", line 107, in parse_request
    song_list = song_gatherer.from_playlist(
  File "/**/venv/lib/python3.8/site-packages/spotdl/search/song_gatherer.py", line 359, in from_playlist
    for result in results:
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 619, in result_iterator
    yield fs.pop().result()
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 437, in result
    return self.__get_result()
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/**/venv/lib/python3.8/site-packages/spotdl/search/song_gatherer.py", line 320, in get_song
    song = from_spotify_url(
  File "/**/venv/lib/python3.8/site-packages/spotdl/search/song_gatherer.py", line 43, in from_spotify_url
    raw_track_meta, raw_artist_meta, raw_album_meta = metadata_provider.from_url(
  File "/**/venv/lib/python3.8/site-packages/spotdl/providers/metadata_provider.py", line 11, in from_url
    raw_track_meta = spotify_client.track(spotify_url)
  File "/**/venv/lib/python3.8/site-packages/spotipy/client.py", line 345, in track
    return self._get("tracks/" + trid, market=market)
  File "/**/venv/lib/python3.8/site-packages/spotipy/client.py", line 297, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/**/venv/lib/python3.8/site-packages/spotipy/client.py", line 267, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/tracks/22ea9e9wspXjaR7qfqfsdS:
 None, reason: None

Other details

Easy to go solution would be to wrap "from_url" with the "retry" decorator (https://pypi.org/project/retry/)

chardebeer commented 2 years ago

I'm having the exact same issue

VictoRPiles commented 2 years ago

Same here

RuslanBM commented 2 years ago

Fix it please

thomasj2710 commented 2 years ago

Experienced the same event today, and songs would not initiate download. Tried with playlists of varying sizes. Single songs would work, but any playlist greater than 3 or 4 tracks would fail.

Silverarmor commented 2 years ago

Navigate to your working directory (where you are running spotDL) and delete the .spotdl-cache file, then try again

In Windows, the default working directory is your user folder C:\Users\yourname\

You can also try reinstall spotDL & its dependencies pip install -U --force spotdl

ryanidk commented 2 years ago

It seems like this may be an issue with spotipy?

HakonHarnes commented 2 years ago

I am also experiencing this issue.

domlysi commented 2 years ago

In my opinion, spotfify-download should handle the http404 or SpotifyException instead just exciting out.

spotify_client.track(spotify_url) Is basically an GET request method.

thomasj2710 commented 2 years ago

To everyone in this thread, doing the following has seemed to work with a playlist of 39 songs:

Navigate to your working directory (where you are running spotDL) and delete the .spotdl-cache file, then try again

In Windows, the default working directory is your user folder C:\Users\yourname\

terrortoon commented 2 years ago

To everyone in this thread, doing the following has seemed to work with a playlist of 39 songs:

Navigate to your working directory (where you are running spotDL) and delete the .spotdl-cache file, then try again

In Windows, the default working directory is your user folder C:\Users\yourname\

I tried it and it still doesn't work.

pktiuk commented 2 years ago

This fix doesn't work (at least on Linux)

Cauldriva commented 2 years ago

I'm experiencing the same issue, not only with big playlists, but also with albums which contain ~16 songs.

domlysi commented 2 years ago

So I fixed it in my fork: https://github.com/domlysi/spotify-downloader

I'm new to contributing, so I don't really know what and how to do it. But you guys can clone the fork and try it.

xnetcat commented 2 years ago

it's already fixed on dev branch. I will release new update later today.

Keep in mind that it's only a temporary fix, I will investigate this issue more thoroughly later this week

Update spotDL from dev

Cauldriva commented 2 years ago

Great to hear. I tried the following workaround which I found on Discord, and it works fine, so this can also be used as a temporary fix:

afbeelding

tmuellerchen commented 2 years ago

For me both "workarrounds" do not work. I got the same error on all playlists with more the 3 or 4 items ...

Maybe it is a restriction on spotify API.

Before I got this error I use the params

--dt 20 --st 10

Now I try with:

--dt 1 --st 1

and everything works fine. no 404 errors

ncarreiro commented 2 years ago

Hello, guys. I don't know if it might be the problem, but make sure your Playlist is in "Public". I just changed mine from "Private" to "Public", and it managed to download the songs. I still get some 404 of some songs, tho, but I think that's common as some of them are not in YouTube.

xnetcat commented 2 years ago

new version has been released with a fix. Please update

pip install -U spotdl