【问题标题】:couldnt write token to cache at: .cache无法将令牌写入缓存:.cache
【发布时间】:2021-10-16 09:23:28
【问题描述】:

run display

运行时会吐出错误,无法将令牌写入缓存位置:.cache,但它仍然设法抓取正在播放的任何内容。每次它发出请求时,它都会重新打开一个身份验证页面。它也不会保存到任何文件中。使用主 python 环境在 pycharm 中一切运行良好。

from spotipy.oauth2 import SpotifyOAuth
import requests
import time
#file locations
file_time_playing = "time_playing.txt"
file_time_playing_ms = "time_playing_ms.txt"
file_time_total = "time_total.txt"
file_time_total_ms = "time_total_ms.txt"


sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id = ".......",
                                              client_secret = ".......",
                                              redirect_uri = "http://localhost:8080",
                                              scope = "streaming"))


song = ""

def track():
   print("======================")
   global song
   global currently_playing
   # print(sp.currently_playing())

   try:
       currently_playing = sp.currently_playing()
       #print(currently_playing)
       if song == str(currently_playing["item"]["name"]):
           print(song)
           play_time()
           return
       else:
           song = str(currently_playing["item"]["name"])
           print(song)

           with open("song.txt", "w", encoding="utf-8") as f:
               f.write(song)
   except:
       pass




starttime = time.time()
while True:
   track()
   time.sleep(0.5 - ((time.time() - starttime) % 0.5))```

【问题讨论】:

    标签: python spotipy


    【解决方案1】:

    我找到了一个指向 git hub 错误的链接,它建议从 .bat 中破坏它我使用下面的链接来解决我的问题 https://github.com/plamere/spotipy/issues/363

    How to run a .py file through a batch file using Command line

    【讨论】:

      猜你喜欢
      • 2018-08-23
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 2016-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多