Hello I've been working on this code that filters my top-200 songs on spotify, filters them by genre, then updates a playlist. Everything has been good until here, the problem is I wanted to implement the spotify reccomendations API to add also some of the spotify reccomended songs. I can't seem to figure out where the problem is, these are the errors I am getting:
HTTP Error for GET to with Params: {'limit': 20, 'seed_genres': 'pop'} returned 404 due to None
Traceback (most recent call last):
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\.venv\Lib\site-packages\spotipy\client.py", line 275, in _internal_call
response.raise_for_status()
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\.venv\Lib\site-packages\requests\models.py", line 1024, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: ;seed_genres=pop
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\test2.py", line 31, in <module>
print(combine())
^^^^^^^^^
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\test2.py", line 24, in combine
recommendations = sp.recommendations(seed_tracks=None,seed_genres=['pop'],seed_artists=None,limit=20)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\.venv\Lib\site-packages\spotipy\client.py", line 1728, in recommendations
return self._get("recommendations", **params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\.venv\Lib\site-packages\spotipy\client.py", line 327, in _get
return self._internal_call("GET", url, payload, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\.venv\Lib\site-packages\spotipy\client.py", line 297, in _internal_call
raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 404, code:-1 - ;seed_genres=pop:
None, reason: None
Process finished with exit code 1
and this is my code:
import spotipy
from spotipy.oauth2 import SpotifyOAuth
# Spotify API credentials
CLIENT_ID = 'xxxxx'
CLIENT_SECRET = 'xxxxxx'
REDIRECT_URI = 'http://localhost:8080/callback'
SCOPE = "user-top-read playlist-modify-public playlist-modify-private"
# Playlist ID for the existing playlist
TARGET_PLAYLIST_ID = '3Eu0FwJvtjDifEJVSzW8m0'
# Initialize Spotify API client
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
redirect_uri=REDIRECT_URI,
scope=SCOPE
))
def combine():
# Calculate how many more tracks are needed to reach 50
seed_tracks = ['0cGG2EouYCEEC3xfa0tDFV','7lQ8MOhq6IN2w8EYcFNSUk','68Dni7IE4VyPkTOH9mRWHr','2cYqizR4lgvp4Qu6IQ3qGN']
recommendations = sp.recommendations(seed_tracks=None,seed_genres=['pop'],seed_artists=None,limit=20)
recommended_track_ids = [track['id'] for track in recommendations['tracks']]
return recommended_track_ids
print(combine())
Hello I've been working on this code that filters my top-200 songs on spotify, filters them by genre, then updates a playlist. Everything has been good until here, the problem is I wanted to implement the spotify reccomendations API to add also some of the spotify reccomended songs. I can't seem to figure out where the problem is, these are the errors I am getting:
HTTP Error for GET to https://api.spotify/v1/recommendations with Params: {'limit': 20, 'seed_genres': 'pop'} returned 404 due to None
Traceback (most recent call last):
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\.venv\Lib\site-packages\spotipy\client.py", line 275, in _internal_call
response.raise_for_status()
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\.venv\Lib\site-packages\requests\models.py", line 1024, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.spotify/v1/recommendations?limit=20&seed_genres=pop
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\test2.py", line 31, in <module>
print(combine())
^^^^^^^^^
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\test2.py", line 24, in combine
recommendations = sp.recommendations(seed_tracks=None,seed_genres=['pop'],seed_artists=None,limit=20)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\.venv\Lib\site-packages\spotipy\client.py", line 1728, in recommendations
return self._get("recommendations", **params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\.venv\Lib\site-packages\spotipy\client.py", line 327, in _get
return self._internal_call("GET", url, payload, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Byte\Documents\Python\Spotify Playlist POP\.venv\Lib\site-packages\spotipy\client.py", line 297, in _internal_call
raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify/v1/recommendations?limit=20&seed_genres=pop:
None, reason: None
Process finished with exit code 1
and this is my code:
import spotipy
from spotipy.oauth2 import SpotifyOAuth
# Spotify API credentials
CLIENT_ID = 'xxxxx'
CLIENT_SECRET = 'xxxxxx'
REDIRECT_URI = 'http://localhost:8080/callback'
SCOPE = "user-top-read playlist-modify-public playlist-modify-private"
# Playlist ID for the existing playlist
TARGET_PLAYLIST_ID = '3Eu0FwJvtjDifEJVSzW8m0'
# Initialize Spotify API client
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
redirect_uri=REDIRECT_URI,
scope=SCOPE
))
def combine():
# Calculate how many more tracks are needed to reach 50
seed_tracks = ['0cGG2EouYCEEC3xfa0tDFV','7lQ8MOhq6IN2w8EYcFNSUk','68Dni7IE4VyPkTOH9mRWHr','2cYqizR4lgvp4Qu6IQ3qGN']
recommendations = sp.recommendations(seed_tracks=None,seed_genres=['pop'],seed_artists=None,limit=20)
recommended_track_ids = [track['id'] for track in recommendations['tracks']]
return recommended_track_ids
print(combine())
Share
Improve this question
edited Feb 3 at 18:07
Andrea Di Campo
asked Feb 3 at 18:05
Andrea Di CampoAndrea Di Campo
111 bronze badge
2 Answers
Reset to default 3It looks like the API has been deprecated. People are discussing the same issue on their community forum.
I faced the same issue for my project, I temporarily used this API https://reccobeats/docs/apis/get-recommendation almost same at Spotify recommendation API