Spotipy invalid access token ? scope problem?

Im doing a simple script to update a playlist but I have an error even if everything looks good: `

The script start, I URI works and give me a token, spotify open to asked me the access but after it fail :

   HTTP Error for PUT to https://api.spotify.com/v1/playlists/6rkyVmrfPEeWkJm01mbhO1 with 
   Params: {} returned 401 due to Invalid access token
   Traceback (most recent call last):
   File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\spotipy\client.py", line 269, in _internal_call
   response.raise_for_status()
   File "C:\Users\xxxx\AppData\Local\Programs\Python\Python311\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
  raise HTTPError(http_error_msg, response=self)
  requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: 
  https://api.spotify.com/v1/playlists/6rkyVmrfPEeWkJm01mbhO1

Python code:

def func():
scope = 'playlist-modify-public'
username = 'myusername'
SPOTIPY_CLIENT_ID = 'xxxxxxxxxxxx'
SPOTIPY_CLIENT_SECRET = 'xxxxxxxxx'

token = util.prompt_for_user_token(username,scope,SPOTIPY_CLIENT_ID,SPOTIPY_CLIENT_SECRET,redirect_uri='https://www.dev.com')
print(token)
sp = spotipy.Spotify(auth="token")

id = 'https://open.spotify.com/playlist/6rkyVmrfPEeWkJm01mbhO1'
playlist_name = 'it works'
playlist_description = 'updated by script'
sp.user_playlist_change_details(username, id, name=playlist_name, description=playlist_description)
func()

here another try :

I get :

py spotify_bot.py 
HTTP Error for PUT to https://api.spotify.com/v1/playlists/6rkyVmrfPEeWkJm01mbhO1 with Params: {} returned 403 due to Not allowed
An exception occurred

Here the code

import spotipy
 from spotipy.oauth2 import SpotifyOAuth
 import json

 def func():
     SCOPE = 'playlist-modify-public'
     USER_ID = 'xifeat'
     REDIRECT_URI = 'http://localhost:3000/callback'
     CLIENT_ID = '6cff431d1dea40f4812460b4721032b0'
     CLIENT_SECRET = 'fb0bcffd4b2b41ac84b9b1d7501dbb80'
     PLAYLIST_ID = '6rkyVmrfPEeWkJm01mbhO1'
     PLAYLIST_NAME = 'test'
     DESCRIPTION = 'Updated !'
     try:    
         auth_manager = SpotifyOAuth(
         scope=SCOPE,
        username=USER_ID,
        redirect_uri=REDIRECT_URI,
        client_id=CLIENT_ID,
        client_secret=CLIENT_SECRET)
    spotify = spotipy.Spotify(auth_manager=auth_manager)

    spotify.user_playlist_change_details(
        user=USER_ID,
        playlist_id=PLAYLIST_ID,
        name=PLAYLIST_NAME,
        description=DESCRIPTION)
except:
    print("An exception occurred")
 func()

enter image description here

`



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)