我的Python脚本遇到了一个问题.代码会执行,但在它显示缓存错误之后:
Couldn't read cache at: .cache
Couldn't write token to cache at: .cache
Couldn't read cache at: .cache
Couldn't write token to cache at: .cache
Couldn't read cache at: .cache
Couldn't write token to cache at: .cache
Couldn't read cache at: .cache
Couldn't write token to cache at: .cache
Couldn't read cache at: .cache
Couldn't write token to cache at: .cache
我正在使用Spotify返回播放列表中的歌曲.然后,我会判断播放列表中的脏话,过滤掉不能播放给子元素听的歌曲.
以下是我使用的代码:
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
spotify_id = "ABC123"
spotify_secret = "456789"
oldies = "738hgt"
kids = "201hgj"
country = "099sdt"
spotify_playlist = country
import lyricsgenius
genius_token = "123456789&ABCEFGHIJKLMNOPQRSTUVWXYZ"
genius = lyricsgenius.Genius(genius_token)
genius.verbose = False
genius.timeout = 100
word_listing = ["bad", "words", "go", "here"]
credentials = SpotifyClientCredentials(client_id=spotify_id, client_secret=spotify_secret)
validate = spotipy.Spotify(auth_manager=credentials)
songs = []
limit = 100
offset = 0
playlist = validate.playlist_tracks(spotify_playlist, limit=limit, offset=offset)
while True:
playlist = validate.playlist_tracks(spotify_playlist, limit=limit, offset=offset)
if not len(playlist['items']):
break
for items in playlist['items']:
info = {'artist': items['track']['artists'][0]['name'], 'title': items['track']['name']}
songs.append(info)
offset += limit
print("Checking playlist...")
for song in songs:
print(f" Checking \"{song['title']}\" by: {song['artist']}")
term = genius.search_song(title=song['title'], artist=song['artist'])
for words in word_listing:
try:
if len(term.lyrics) > 10000:
break
if words in term.lyrics.lower():
print(f" *Found \"{words}\" in \"{song['title']}\" by: {song['artist']}")
continue
except AttributeError:
print(f" *Unable to find lyrics for: \"{song['title']}\" by: {song['artist']}")
break
except:
print(f" *Unable to connect to service, moving on...")
我已经替换了本例的所有变量值.有人告诉我,这是Spotify API的一个问题;这只是一个可以忽略的警告.
我还被告知这是一个权限问题,Spotify想要写入缓存目录,但它没有这样做的正确权限.
我真的不确定是什么导致了这个问题.错误出现在脚本的开头,然后在它显示之后,脚本的其余部分成功运行.
是不是我的某个论点或陈述中有什么东西导致了这种情况?