<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Token refreshes suddenly failing in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Token-refreshes-suddenly-failing/m-p/5371961#M4445</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Premium&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Germany&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;MacBook Air 2020 late / Raspberry Pi (running server side code)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;MacOS Monterey / Debian Bullseye&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the python code I'm using to call the API:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def _renew_spotify_credentials(refresh_token: str) -&amp;gt; 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()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: added code snippet&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 23 Apr 2022 12:19:12 GMT</pubDate>
    <dc:creator>smorrin28</dc:creator>
    <dc:date>2022-04-23T12:19:12Z</dc:date>
    <item>
      <title>Token refreshes suddenly failing</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Token-refreshes-suddenly-failing/m-p/5371961#M4445</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Premium&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Germany&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Device&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;MacBook Air 2020 late / Raspberry Pi (running server side code)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Operating System&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;MacOS Monterey / Debian Bullseye&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the python code I'm using to call the API:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def _renew_spotify_credentials(refresh_token: str) -&amp;gt; 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()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: added code snippet&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Apr 2022 12:19:12 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Token-refreshes-suddenly-failing/m-p/5371961#M4445</guid>
      <dc:creator>smorrin28</dc:creator>
      <dc:date>2022-04-23T12:19:12Z</dc:date>
    </item>
  </channel>
</rss>

