首页 > 解决方案 > 为什么我在 python 中得到一个带有 spotipy 的 attributeError?

问题描述

我按照https://www.section.io/engineering-education/spotify-python-part-1/对spotipy 的介绍,但由于某种原因,我得到了一个 AttributeError。有人经历过类似的吗?

这是我在 main.py 中的代码:

import spotipy
from spotipy.oauth2 import SpotifyOAuth
import cred

scope = "user-read-recently-played"

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=cred.client_id, client_secret= cred.client_secret, redirect_uri=cred.redirect_url, scope=scope))

results = sp.current_user_recently_played()
for idx, item in enumerate(results['items']):
    track = item['track']
    print(idx, track['artists'][0]['name'], " – ", track['name'])

这是我在 cred.py 中的代码(我不确定我是否使用 redirect_url 做对了):

client_ID = 'ed8de3e9b4d64e63a7e7251b5e5d7059'
client_SECRET = 'c5e0dcd1d01e48ffac80b22bc1fbe929'
redirect_url = 'http://localhost:8888/callback'

标签: pythonspotipy

解决方案


推荐阅读