Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

[Desktop][Python] Cant get request to current track Api (maybe dublicate post)

Solved!

[Desktop][Python] Cant get request to current track Api (maybe dublicate post)

Hello,
my proplem is if I run the code/call the function I get a 404 error but the structur of the api is correct, bc i can call other things with the token + "url". Can somebody help me or has the same issue ?

Code:

def get_current_track(token😞
    headers = get_auth_header(token)
    query = "?market=DE"
    query_url = url + query
    result = get(query_url, headers=headers)
    json_result = result.json()
    return json_result

 

 

Thank you

Reply

Accepted Solutions
Marked as solution

You can use code from this answer on Stack Overflow:

https://stackoverflow.com/a/75292843/7111585

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

View solution in original post

5 Replies

Code of how you get an access token is missing.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

client_id = os.getenv("CLIENT_ID")
client_secret = os.getenv("CLIENT_SECRET")

def get_token():
    auth_string = client_id + ":" + client_secret
    auth_bytes = auth_string.encode("utf-8")
    auth_base64 = str(base64.b64encode(auth_bytes), "utf-8")

    headers = {
        "Authorization": "Basic " + auth_base64,
        "Content-Type": "application/x-www-form-urlencoded"
    }
    data = {"grant_type": "client_credentials"}
    result = post(url, headers=headers, data=data)
    json_result = json.loads(result.content)
    token = json_result["access_token"]
    return token

def get_auth_header(token😞
    return {"Authorization": "Bearer " + token}
 
 
here you go.

Since the Client Credentials flow does not include authorization, only endpoints that do not access user information can be accessed. Therefore, in this case, you should use a different Authorization method that lets you log in.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

And what Authorization should I use, that it works fine ?

Marked as solution

You can use code from this answer on Stack Overflow:

https://stackoverflow.com/a/75292843/7111585

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Suggested posts

Type a product name