如何解决Python 无法写入缓存文件
我目前正在开发一个用于在 Python 中发现 API 的项目。为此,我使用了 spipy 库。为了让程序正常工作,您需要有一个访问令牌。这保存在 .cache-username 文件中。访问令牌需要非常小时刷新。这会随着我设置代码的方式自动发生。我遇到的问题是,当我使用 python 3 在 Windows 10 pc 上运行代码时,写入缓存文件并保持程序处于活动状态没有问题,但是当我在 Raspberry PI 上运行程序时也使用 python 3它会在 30-60 分钟后崩溃并出现以下错误:
Couldn't write token to cache at: .cache-username.
我已经尝试通过以下方式为缓存文件提供所需的所有权限:
sudo chmod +rwx .cache-username
但这并没有解决问题。
有谁知道是什么导致了这个问题以及如何解决它?
程序本身:
import spotipy
import spotipy.util as util
clientID = "my_client_id"
clientSec = "my_client_secret_key"
# The scopes defines how much you are allowed
scope = "user-read-currently-playing"
username = "my_user_name"
# loop to keep updating
while True:
# Gets a token for spotify and should keep it updated
token = util.prompt_for_user_token(username,scope,client_id=clientID,client_secret=clientSec,redirect_uri="http://localhost/Spotify/callback.php")
sp = spotipy.Spotify(auth=token)
# Returns some data about the current playing song
results = sp.currently_playing(market=None)
# If there is a song playing than show the song name
if results:
# Song info
songName = results["item"]["name"]
# print(songName)
time.sleep(0.4)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。