Announcements
The Spotify Stars Program: Celebrating Values Week!

Help Wizard

Step 1

NEXT STEP

403 Error Spotipy Playback Issues Playlist and Songs

403 Error Spotipy Playback Issues Playlist and Songs

.

Plan

Premium

 

Country

France

 

Operating System

Windows 10

 

My Question or Issue

Was trying to play a playlist using the spotipy library and my credentials. Was able to get the playlist metadata but when trying to play a song or a playlist I got a 403  error saying that my account is not prenium even though it is. Or is it because it is a family prenium account ?

Do you have any idea or similar issues with the spotipy library ?

Reply
8 Replies

Hey @Narakap, thanks for reaching out!


That doesn't sound right! First things first, could you make sure you're authenticated with the right account? You can check by verifying that:

spotipy.me()

 shows the correct username. Let me know if that works.

 

Have a good one!

Hubo

HuboSpotify 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.

Hello, Ty for your reply.

When trying your command I got that error :

 

HTTP Error for GET to https://api.spotify.com/v1/me/ returned 401 due to Unauthorized.

 

I checked and I got the latest version of spotipy avalaible here https://github.com/plamere/spotipy.git 

Here is Mmy code between

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import json

client_credentials_manager = SpotifyClientCredentials(client_id=my_client_id,client_secret=my_client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

sp.me()

Hey @Narakap, thanks for getting back to me!

 

Gotcha! Let's dive into this. You can use export commands (in Terminal) to set the client_id and client_secret variables for your OS. 

export SPOTIPY_CLIENT_ID=client_id_here
export SPOTIPY_CLIENT_SECRET=client_secret_here

// on Windows, use `SET` instead of `export`

 

Alternatively, you can in Python set them with these:

os.environ["SPOTIPY_CLIENT_ID"] = "(my client id)"
os.environ["SPOTIPY_CLIENT_SECRET"] = "(my client secret)"

 

There's more information about this here: https://github.com/plamere/spotipy. Let me know if that helps here!

 

Have a good one,

Hubo 

HuboSpotify 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.

Ty for trying to help me.

 

I set the credentials like showed here https://github.com/plamere/spotipy

 

I managed to run the example code the gave without error :

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import json
import os

os.environ["SPOTIPY_CLIENT_ID"] = my_client_id
os.environ["SPOTIPY_CLIENT_SECRET"] = my_secret_id

sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())

results = sp.search(q='weezer', limit=20)
for idx, track in enumerate(results['tracks']['items']):
    print(idx, track['name'])

 

 

But when I tried sp.me() it gave me the same error...

 

HTTP Error for GET to https://api.spotify.com/v1/me/ returned 401 due to Unauthorized.

 

Just to be sure again I checked and I am prenium.

 

family.PNG

Hey @Narakap,

 

Hmm, got it! You might need to adjust the scope of your authorization request to see the information from the ‘me’-endpoint. Are you able to access the other ‘scope-less’ endpoints? Let me know!

 

Have a good one,

Hubo

HuboSpotify 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.

Hi all,

Im having the same problem with credentials ids. I've tried with:

os.environ["SPOTIPY_CLIENT_ID"] = my_client_id
os.environ["SPOTIPY_CLIENT_SECRET"] = my_secret_id
set SPOTIPY_CLIENT_ID=client_id
set SPOTIPY_CLIENT_SECRET=client_secret
client_credentials_manager = SpotifyClientCredentials(client_id=my_client_id,client_secret=my_client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

In all the different ways, after doing "sp.me()" or "sp.current_user()" I get: "requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://api.spotify.com/v1/me/"

 

When requesting "sp.current_user_recently_played(limit=50)" i get: "HTTP Error for GET to https://api.spotify.com/v1/me/player/recently-played returned 403 due to Insufficient client scope"

 

It's my second project using Spotify API from Python, and this time I'm having big trouble just by getting the credentials.

 

Any help would be great!

Thanks!

The Client Credentials Flow (implemented by `SpotifyClientCredentials` in spotipy) does NOT support authorizing for a user. It's only used for requests that don't access user data. Obviously, `sp.me()` accesses user data. You need to use `SpotifyOAuth` or `SpotifyPKCE` for authorization instead.

Suggested posts