[Python] Trying to get Access token and Refresh token from Spotify API (Python)

Discussão em 'Python' iniciado por Stack, Fevereiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    I managed to get the auth code from the URI and I'm using it has explained from the documentation. Double checked client_id and client_secret to be sure everything is allright. Same thing for URI's url and Token requests' url. I can't wrap my head around on why this happens

    Here's my code

    parameters = {
    "grant_type":"authorization_code",
    "code": code,
    "redirect_uri":SPOTIFY_URI
    }

    auth_string = base64.urlsafe_b64encode(f"{SPOTIFY_ID}:{SPOTIFY_SECRET}".encode("utf-8"))

    headers = {
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization": f"Basic {auth_string.decode('utf-8')}",
    }

    response = requests.post(
    "https://accounts.spotify.com/api/token", params=parameters,
    headers=headers
    )

    response.raise_for_status()
    print(response)


    And here's the error message that is raised:

    requests.exceptions.HTTPError: 400 Client Error: Bad Request for url:<my_token_url>


    Can anyone help?

    Continue reading...

Compartilhe esta Página