admin管理员组文章数量:1394770
I have started learning about and experimenting with the Spotify API recently. So, I wrote the following code to fetch audio features like acousticness, danceability etc. of my liked/saved songs:
def get_audio_features(token, track_id):
url = f"/{track_id}"
headers = {"Authorization": f"Bearer {token}"}
result = get(url, headers=headers)
json_result = json.loads(result.content)
return json_result
scope = "user-library-read"
redirect_url = get_authorization_code()
auth_code = extract_auth_code(redirect_url)
access_token = get_access_token(auth_code)
print(f"✅ Access Token: {access_token}")
df = pd.read_csv('liked_songs.csv')
track_features_list = []
for i, track_id in enumerate(df['track_id']):
features = get_audio_features(access_token, track_id)
track_features_list.append(features)
feature_df = pd.DataFrame(track_features_list)
print(feature_df.head())
The problem is that I didn't save the resulting dataframe. Now, when I try to rerun the code to save it in a csv, all queries return the response code 304. I have no idea how to fetch the already cached response too.
I have tried clearing the browser cache, cookies and history. I even tried modifying the headers and url to force a new fresh request but stil getting the status 304.
url = f"/{track_id}?nocache={int(time.time())}"
headers = {"Authorization": f"Bearer {token}",
"Cache-Control": "no-cache, no-store, must-revalidate",
"Pragma": "no-cache",
"Expires": "0"
}
Do i just have to wait a few days to be able to resend the requests? I would love to understand why this is happening and how do I go about fixing this.
本文标签: pythonHow do I get responses from Spotify API after status code 304Stack Overflow
版权声明:本文标题:python - How do I get responses from Spotify API after status code 304? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744103530a2590969.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论