最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How do I get responses from Spotify API after status code 304? - Stack Overflow

programmeradmin5浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论