This is a code I am using to pull data from Spotify website using Spotipy library and python. I can pull data with authentication but there also I am only able to pull my user data and through their search API. But I want to pull any data just by giving the URL and without authentication.
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
# Spotify API credentials from your app
client_id = 'my_client_id'
client_secret = 'my_client_secret'
#Authentication - without user
client_credentials_manager = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
sp = spotipy.Spotify(client_credentials_manager = client_credentials_manager)
playlist_link = ";
playlist_URI = playlist_link.split("/")[-1].split("?")[0]
track_uris = [x["track"]["uri"] for x in sp.playlist_tracks(playlist_URI)["items"]]
But I am getting the below error
HTTP Error for GET to with Params: {'limit': 100, 'offset': 0, 'fields': None, 'market': None, 'additional_types': 'track'} returned 404 due to Resource not found
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
File ~\AppData\Roaming\Python\Python310\site-packages\spotipy\client.py:275, in Spotify._internal_call(self, method, url, payload, params)
270 response = self._session.request(
271 method, url, headers=headers, proxies=self.proxies,
272 timeout=self.requests_timeout, **args
273 )
--> 275 response.raise_for_status()
276 results = response.json()
File ~\AppData\Roaming\Python\Python310\site-packages\requests\models.py:1021, in Response.raise_for_status(self)
1020 if http_error_msg:
-> 1021 raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: ;offset=0&additional_types=track
During handling of the above exception, another exception occurred:
SpotifyException Traceback (most recent call last)
Cell In[26], line 3
1 playlist_link = ";
2 playlist_URI = playlist_link.split("/")[-1].split("?")[0]
----> 3 track_uris = [x["track"]["uri"] for x in sp.playlist_tracks(playlist_URI)["items"]]
File ~\AppData\Roaming\Python\Python310\site-packages\spotipy\client.py:703, in Spotify.playlist_tracks(self, playlist_id, fields, limit, offset, market, additional_types)
687 """ Get full details of the tracks of a playlist.
688
689 Parameters:
(...)
696 valid types are: track and episode
697 """
698 warnings.warn(
699 "You should use `playlist_items(playlist_id, ...,"
700 "additional_types=('track',))` instead",
701 DeprecationWarning,
702 )
--> 703 return self.playlist_items(playlist_id, fields, limit, offset,
704 market, additional_types)
File ~\AppData\Roaming\Python\Python310\site-packages\spotipy\client.py:727, in Spotify.playlist_items(self, playlist_id, fields, limit, offset, market, additional_types)
715 """ Get full details of the tracks and episodes of a playlist.
716
717 Parameters:
(...)
724 valid types are: track and episode
725 """
726 plid = self._get_id("playlist", playlist_id)
--> 727 return self._get(
728 f"playlists/{plid}/tracks",
729 limit=limit,
730 offset=offset,
731 fields=fields,
732 market=market,
733 additional_types=",".join(additional_types)
734 )
File ~\AppData\Roaming\Python\Python310\site-packages\spotipy\client.py:327, in Spotify._get(self, url, args, payload, **kwargs)
324 if args:
325 kwargs.update(args)
--> 327 return self._internal_call("GET", url, payload, kwargs)
File ~\AppData\Roaming\Python\Python310\site-packages\spotipy\client.py:297, in Spotify._internal_call(self, method, url, payload, params)
290 reason = None
292 logger.error(
293 'HTTP Error for %s to %s with Params: %s returned %s due to %s',
294 method, url, args.get("params"), response.status_code, msg
295 )
--> 297 raise SpotifyException(
298 response.status_code,
299 -1,
300 f"{response.url}:\n {msg}",
301 reason=reason,
302 headers=response.headers,
303 )
304 except requests.exceptions.RetryError as retry_error:
305 request = retry_error.request
SpotifyException: http status: 404, code:-1 - ;offset=0&additional_types=track:
Resource not found, reason: None
Can anyone let me know where am I going wrong an also how do I get data for the top 1000 songs on Spotify every day?