Spotipy:readthedocs的简单代码出现异常

用户

当我从Spotify's Docs运行这个简单代码时:

import spotipy

birdy_uri = 'spotify:artist:2WX2uTcsvV5OnS0inACecP'
spotify = spotipy.Spotify()

results = spotify.artist_albums(birdy_uri, album_type='album')
albums = results['items']
while results['next']:
    results = spotify.next(results)
    albums.extend(results['items'])

for album in albums:
    print(album['name'])

我有个例外:

^{pr2}$


已被浏览了3107次
更新日期: 2020-10-26 06:44:57
2 个回答
fefe Tyson

spotifywebapi最近更新了,需要对各种请求进行授权。在

使用authorized requests可以解决这个问题。在

评论 - 2020年8月7日 23:23
fefe Tyson

您需要使用您的Spotify应用凭据(客户端ID和客户端密码),从www.developer.spotify.com,将其分配给一个变量并将其用作对象。在

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials

cid ="Your-client-ID" 
secret = "Your-client-secret"

client_credentials_manager = SpotifyClientCredentials(client_id=cid, client_secret=secret) 
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

#Then run your query
results = sp.artist_albums(birdy_uri, album_type='album'))

#### ETC ######

更多信息:Client Credential Flow

评论 - 2020年8月7日 23:23

最新Python问答

推荐Python问答