Plan
Premium
Country
Germany
Device
MacBook Air 2020 late / Raspberry Pi (running server side code)
Operating System
MacOS Monterey / Debian Bullseye
My Question or Issue
I have a simple script running on my raspberry pi that runs every hour (invoked by cron), makes some calls to the spotify API and one of them is refreshing an API token. While this script has worked fine for the last two months, I noticed that it worked fine until now - when trying to refresh an API token, the request fails with the status code 400 and the message "Malformed request". Even manually using a HTTP client to refresh the token doesn't work. I'm not sure if there's some kind of bug or if it's my fault. Is anyone here experiencing the same error?
This is the python code I'm using to call the API:
def _renew_spotify_credentials(refresh_token: str) -> dict:
client_id = os.getenv("SPOTIFY_CLIENT_ID")
client_secret = os.getenv("SPOTIFY_CLIENT_SECRET")
basic_token = base64.b64encode(
f"{client_id}:{client_secret}".encode("ascii")).decode("ascii")
r = requests.get(
"https://accounts.spotify.com/api/token",
headers={
"Authorization": f"Basic {basic_token}",
"Content-Type": "application/x-www-form-urlencoded",
},
data={
"grant_type": "refresh_token",
"refresh_token": refresh_token,
}
)
return r.json()
Edit: added code snippet