Reputation: 11
I am looking to retrieve audio features of a specific track using the spotipy library for the Spotify API. However, I am first trying to see if I can use spotipy to get some information. But when I copy the literal code of the spotipy documentation, it does not work. It geves the error: HTTP Error for GET to HTTP Error for GET to https://api.spotify.com/v1/search with Params: {'q': 'year:2018', 'limit': 50, 'offset': 1000, 'type': 'track', 'market': None} returned 404 due to Not found. or other HTTP errors This seems strange since I litterly use the code provided in the documentation. I have tried this with several different code and everywhere I get the same error. I must do something wrong but I haven't got a clue what.
This is the code:
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
cid = 'ID'
secret = 'key'
client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret)
sp = spotipy.Spotify(client_credentials_manager
=
client_credentials_manager)
artist_name = []
track_name = []
popularity = []
track_id = []
for i in range(0,10000,50):
track_results = sp.search(q='year:2018', type='track', limit=50,offset=i)
for i, t in enumerate(track_results['tracks']['items']):
artist_name.append(t['artists'][0]['name'])
track_name.append(t['name'])
track_id.append(t['id'])
popularity.append(t['popularity'])
track_dataframe = pd.DataFrame({'artist_name' : artist_name, 'track_name' : track_name, 'track_id' : track_id, 'popularity' : popularity})
print(track_dataframe.shape)
track_dataframe.head()
Upvotes: 0
Views: 1893
Reputation: 546
As per Spotify's API documentation, the maximum amount of items that can be returned in a search is 1000, that's why 950 is the largest offset that still has results.
Upvotes: 1