为什么在 Spotipy 中进行身份验证时会出现“无法读取缓存:.cache-<My Username>”警告并且代码 运行 无限期出现?

Why does the 'couldn't read cache at: .cache-<My Username> ' warning appear and the code run indefinitely when authenticating in Spotipy?

我正在尝试使用以下代码在 Google Colab 中使用 spotipy 访问我喜欢的歌曲:

import spotipy 
from spotipy.oauth2 import SpotifyClientCredentials

# credentials
cid ='<My Client ID>'
secret = '<My Client Secret>'
username = '<My Username>'
scope = 'user-library-read'
redirect_uri='http://localhost:8888/callback/'

# access user
client_credentials_manager = spotipy.oauth2.SpotifyOAuth(
    scope=scope,
    username=username,
    client_id=cid,
     client_secret=secret,
     redirect_uri=redirect_uri)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

# a user saved song
sp.current_user_saved_tracks(limit=1)

然而,每当我 运行 它时,我都会返回“无法读取缓存:.cache-'my username' 和代码 运行s 无限期。为什么会发生这种情况,我该如何解决?

问题是浏览器无法在 Google Colab 中打开,因此他们可以 运行 无限期地解决此设置 open_browser=False 并且它将在新选项卡中打开并且所有将工作正常。无法读取缓存警告将在第一个 运行.

后消失
import spotipy 
from spotipy.oauth2 import SpotifyClientCredentials

# credentials
cid ='<My Client ID>'
secret = '<My Client Secret>'
username = '<My Username>'
scope = 'user-library-read'
redirect_uri='http://localhost:8888/callback/'

# access user
client_credentials_manager = spotipy.oauth2.SpotifyOAuth(
    scope=scope,
    username=username,
    client_id=cid,
     client_secret=secret,
      redirect_uri=redirect_uri,
      open_browser=False)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

# a user saved song
sp.current_user_saved_tracks(limit=1)