Python Spotipy刷新访问令牌Oauth2

Python Spotipy刷新访问令牌Oauth2,python,spotipy,Python,Spotipy,我正在尝试制作一个程序,从spotify播放列表中删除歌曲。目前,我无法刷新身份验证令牌,尽管已将它们保存在硬盘上,并在创建oauth对象时指定了缓存路径 from bottle import route, run, request import spotipy from spotipy import oauth2 import time PORT_NUMBER = 8080 SPOTIPY_CLIENT_ID = 'e1bb48ed8b594aeb9faf74f7e8915de7' SPOT

我正在尝试制作一个程序,从spotify播放列表中删除歌曲。目前,我无法刷新身份验证令牌,尽管已将它们保存在硬盘上,并在创建oauth对象时指定了缓存路径

from bottle import route, run, request
import spotipy
from spotipy import oauth2
import time

PORT_NUMBER = 8080
SPOTIPY_CLIENT_ID = 'e1bb48ed8b594aeb9faf74f7e8915de7'
SPOTIPY_CLIENT_SECRET = 'dd6de8b7a0324d6ebf1fc0591e8e3220'
SPOTIPY_REDIRECT_URI = 'http://localhost:8080'
SCOPE = 'playlist-modify-public'
tracks = ['6DCZcSspjsKoFjzjrWoCdn']



def remove(sp_oauth):

    access_token = ""

    token_info = sp_oauth.get_cached_token()

    if token_info:
        if sp_oauth.is_token_expired:
            token_info = sp_oauth.refresh_access_token(token_info['refresh_token'])
            access_token = token_info['access_token']
        else:
            print ("Found cached token!")
            access_token = token_info['access_token']

    if access_token:
        print ("Access token available! Trying to get user information...")
        sp = spotipy.Spotify(access_token)
        results = sp.current_user_playlists()
        userinfo = sp.current_user()
        userid = userinfo['id']
        for items in results['items']:
            if userid == items['owner']['id']:
                sp.user_playlist_remove_all_occurrences_of_tracks(items['owner']['id'],items['id'],tracks)
                print("removed from " + items['owner']['display_name'] + " s list  " + items['name'])




example =oauth2.SpotifyOAuth( SPOTIPY_CLIENT_ID, SPOTIPY_CLIENT_SECRET,SPOTIPY_REDIRECT_URI,scope=SCOPE,cache_path=r'C:\Users\rrako\AppData\Local\Programs\Python\Python38-32\Caches\example')

remove(example)
我得到的错误是

Traceback (most recent call last):
  File "C:\Users\rrako\AppData\Local\Programs\Python\Python38-32\unfollowLists.py", line 212, in <module>
    remove(blake)
  File "C:\Users\rrako\AppData\Local\Programs\Python\Python38-32\unfollowLists.py", line 63, in remove
    if sp_oauth.is_token_expired:
AttributeError: 'SpotifyOAuth' object has no attribute 'is_token_expired'
回溯(最近一次呼叫最后一次):
文件“C:\Users\rrako\AppData\Local\Programs\Python\Python38-32\unfollowLists.py”,第212行,在
移除(布莱克)
文件“C:\Users\rrako\AppData\Local\Programs\Python\Python38-32\unfollowLists.py”,第63行,删除
如果sp_oauth.is_token_过期:
AttributeError:'SpotifyOAuth'对象没有属性'is\u token\u expired'

我拥有的spotipy版本是2.4.4

更新您的spotipy版本,令牌应该自动刷新

pip3 install spotipy --upgrade

更新您的spotipy版本,令牌将自动刷新

pip3 install spotipy --upgrade