名称 'sp' 未一一定义

name 'sp' is not defined spottily

我正在使用 numpy 和 spotipy 检索我的播放列表。这是我遇到问题的代码

def get_features_for_playlist(uri):
    playlist_id = uri.split(':')[2]
    results = sp.user_playlist(username, playlist_id)

它总是给我错误

NameError: name 'sp' is not defined

有人可以帮助我吗?我尝试搜索 spottily 文档,但它显示的代码与我在此处使用的代码相同。

根据报错,尝试添加:

from spotipy import Spotify as sp

作为代码的第一行,您似乎没有导入 spotipy

确保你写:

sp = spotipy.Spotify()