Fehler beim Abziehen von Daten von Spotify mithilfe der Python Library SpotipyPython

Python-Programme
Anonymous
 Fehler beim Abziehen von Daten von Spotify mithilfe der Python Library Spotipy

Post by Anonymous »

Dies ist ein Code, den ich verwenden kann, um Daten von der Spotify -Website mit der Spotpy Library und Python zu ziehen. Ich kann die Authentifizierung durch die Authentifizierung ziehen, aber ich bin auch nur in der Lage, meine Benutzerdaten und über ihre Such -API zu ziehen. Aber ich möchte alle Daten ziehen, indem ich die URL und ohne Authentifizierung angibt. < /P>

Code: Select all

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 = "https://open.spotify.com/playlist/37i9dQZEVXbNG2KDcFcKOF?si=1333723a6eff4b7f"
playlist_URI = playlist_link.split("/")[-1].split("?")[0]
track_uris = [x["track"]["uri"] for x in sp.playlist_tracks(playlist_URI)["items"]]
< /code>
, aber ich erhalte den folgenden Fehler < /p>
HTTP Error for GET to https://api.spotify.com/v1/playlists/37i9dQZEVXbNG2KDcFcKOF/tracks 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: https://api.spotify.com/v1/playlists/37i9dQZEVXbNG2KDcFcKOF/tracks?limit=100&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 = "https://open.spotify.com/playlist/37i9dQZEVXbNG2KDcFcKOF?si=1333723a6eff4b7f"
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 - https://api.spotify.com/v1/playlists/37i9dQZEVXbNG2KDcFcKOF/tracks?limit=100&offset=0&additional_types=track:
Resource not found, reason: None
Kann mich jemand wissen lassen, wohin ich falsch gehe und ich habe auch Daten für die Top 1000 -Songs auf Spotify jeden Tag?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post