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

INVALID_CLIENT: invalid client

INVALID_CLIENT: invalid client

I'm trying to develop a test app using Python and spotipy.

Everything worked fine yesterday. But today when the app tries to obtain a token, I'm getting a browser window opened saying "INVALID_CLIENT: Invalid client".

The actual code looks like this:

 

import spotipy
[...]
scope="playlist-read-collaborative playlist-modify-public playlist-read-private playlist-modify-private user-read-email user-read-private user-library-modify user-library-read"
spotify=spotipy.Spotify(auth_manager=spotipy.SpotifyOAuth(
client_id='1de87466we774e0a913abbe49181e718',
client_secret='<my_secret_here>',
scope=scope,
redirect_uri="http://127.0.0.1:9009/"))
[...]
playlist=spotify.user_playlist_create('<myuser>',"Test playlist 1",public=True)
[...]

 

As soon as I reach the playlist creation part, the library notices that it doesn't have current token so it tries to authenticate me to get one.

It ends with browser opening a window for

https://accounts.spotify.com/authorize?client_id=1de87466we774e0a913abbe49181e718&response_type=code&redirect_uri=http%3A%2F%2F127.0.0.1%3A9009%2F&scope=playlist-read-collaborative+playlist-modify-public+playlist-read-private+playlist-modify-private+user-read-email+user-read-private+user-library-modify+user-library-read

with said "INVALID_CLIENT: invalid client" message from a 400 Bad Request response.

The client id is the proper one - I did copy-paste it from my dashboard and I checked it several times. The secret also is OK (I even reset the secret just to be on the safe side).

The most interesting thing is that I think it used to work properly and now it's not working.

I thought that maybe the app got temporarily blocked because of hitting rate limits but as far as I know, the urllib3 on which spotipy is built honors the 429 and Retry-After header. Anyway I'd expect a 429 response instead of a 400 Bad Request

Any ideas? Because I'm stuck here 😕

Reply
3 Replies

**bleep**. I feel so stupid. I must have checked it a thousand times and still got a typo. There is one "2" that somehow got changed into "w" in the client_id parameter. I have no idea how I managed to do it since I tried copy-pasting it to be sure that I didn't actually make a typo.

Anyway, it seems that's solved.

Im still having this exact problem, any adivice 

 

import openai
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import json

# Load the API key from a file
with open("key.txt", "r") as key_file:
api_key = key_file.read().strip()

openai.api_key = api_key

# Define the user message
username = input("Enter Spotify Username: ")
book_name = input("Enter Book Name/Movie Title: ")
author_name = input("Enter Author/Movie Director: ")
book_input = f"based on the synopsis, country of origin, language, and vibe of the book, Please provide a filled-out JSON file in this format {{\n \"playlist_name\": \"\",\n \"playlist_description\": \"\",\n \"playlist_songs\": [\"\"]\n}}\nWith 10 songs from the last 50 years that fit the vibe of the book/movie \"{book_name}\" by {author_name} for the spotify api. Do not respond with anything other than the JSON file. If you can include songs from the soundtrack. The songs should be relevant to the intended audience, setting of book, etc.,. Do not respond with anything other than the JSON file."
user_message = {"role": "user", "content": book_input}

# Create a chat completion request
completion = openai.ChatCompletion.create(
model='gpt-3.5-turbo',
messages=[user_message]
)

# Extract and parse the assistant's reply as JSON
assistant_reply = completion['choices'][0]['message']['content']
playlist_info = json.loads(assistant_reply)

# Spotify API credentials
client_id = 'aaaaaaaaaa'
client_secret = "bbbbbbbbbb"
redirect_uri = "http://localhost:8080/"

# User-specific settings
scope = 'playlist-modify-public'

try:
# Authenticate with Spotify
token = SpotifyOAuth(scope=scope, username=username, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
spotifyObject = spotipy.Spotify(auth_manager=token)

# Create a new playlist
playlist_name = playlist_info['playlist_name']
playlist_description = playlist_info['playlist_description']

playlist = spotifyObject.user_playlist_create(user=username, name=playlist_name, public=True, description=playlist_description)
print(f"Playlist '{playlist_name}' created successfully!")

# Add songs to the playlist
list_of_songs = []
for song in playlist_info['playlist_songs']:
result = spotifyObject.search(q=song)
if result['tracks']['items']:
list_of_songs.append(result['tracks']['items'][0]['uri'])

# Find the new playlist
prePlaylist = spotifyObject.user_playlists(user=username)
playlist_id = prePlaylist['items'][0]['id']

# Add songs to the playlist
if list_of_songs:
spotifyObject.user_playlist_add_tracks(user=username, playlist_id=playlist_id, tracks=list_of_songs)
print(f"Songs added to the playlist '{playlist_name}' successfully!")
else:
print("No songs were added to the playlist.")
except Exception as e:
print(f"Error: {e}")

@wyanaveen, you can try to add the playlist-modify-private and the playlist-read-private scopes.

Suggested posts