[GH-ISSUE #225] Authorisation Code Flow Issues #117

Closed
opened 2026-02-27 23:20:54 +03:00 by kerem · 5 comments
Owner

Originally created by @stingrai24 on GitHub (Oct 27, 2017).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/225

I have been following the documentation at http://spotipy.readthedocs.io/en/latest/ and I have managed to get Client Credentials Flow to work, meaning that I can write code which accesses public areas of Spotify. However, when trying to authorise personal accounts through Authorisation Code Flow, I keep getting the same error: "spotipy.oauth2.SpotifyOauthError: Bad Request" .
I have followed the instructions exactly, so I do not know what I have done wrong. Could someone please help?

Originally created by @stingrai24 on GitHub (Oct 27, 2017). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/225 I have been following the documentation at http://spotipy.readthedocs.io/en/latest/ and I have managed to get Client Credentials Flow to work, meaning that I can write code which accesses public areas of Spotify. However, when trying to authorise personal accounts through Authorisation Code Flow, I keep getting the same error: "spotipy.oauth2.SpotifyOauthError: Bad Request" . I have followed the instructions exactly, so I do not know what I have done wrong. Could someone please help?
kerem closed this issue 2026-02-27 23:20:55 +03:00
Author
Owner

@ritiek commented on GitHub (Oct 27, 2017):

It would be much more easier to debug if you were to share your code snippet (of course removing any sensitive data). 😄

<!-- gh-comment-id:340025859 --> @ritiek commented on GitHub (Oct 27, 2017): It would be much more easier to debug if you were to share your code snippet (of course removing any sensitive data). :smile:
Author
Owner

@stingrai24 commented on GitHub (Oct 27, 2017):

This is the code and the error I get:

import sys
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import spotipy.util as util

username = input("Username: ")
scope = 'user-library-read'

token = util.prompt_for_user_token(username,scope,client_id='********',client_secret='*****',redirect_uri='http://localhost/')

if token:
    sp = spotipy.Spotify(auth=token)
    results = sp.current_user_saved_tracks()
    for item in results['items']:
        track = item['track']
        print (track['name'] + ' - ' + track['artists'][0]['name'])
else:
    print ("Can't get token for", username)

The error is:
spotipy.oauth2.SpotifyOauthError: Bad Request

<!-- gh-comment-id:340036150 --> @stingrai24 commented on GitHub (Oct 27, 2017): This is the code and the error I get: ``` import sys import spotipy from spotipy.oauth2 import SpotifyClientCredentials import spotipy.util as util username = input("Username: ") scope = 'user-library-read' token = util.prompt_for_user_token(username,scope,client_id='********',client_secret='*****',redirect_uri='http://localhost/') if token: sp = spotipy.Spotify(auth=token) results = sp.current_user_saved_tracks() for item in results['items']: track = item['track'] print (track['name'] + ' - ' + track['artists'][0]['name']) else: print ("Can't get token for", username) ``` The error is: `spotipy.oauth2.SpotifyOauthError: Bad Request`
Author
Owner

@ritiek commented on GitHub (Oct 27, 2017):

Please edit your post to remove your client id and client secret. Be sure to revoke them too.

<!-- gh-comment-id:340038048 --> @ritiek commented on GitHub (Oct 27, 2017): Please edit your post to remove your client id and client secret. Be sure to revoke them too.
Author
Owner

@stingrai24 commented on GitHub (Oct 27, 2017):

Thanks, didn't notice I'd left that in aha!

Any idea what's causing the error?

<!-- gh-comment-id:340039961 --> @stingrai24 commented on GitHub (Oct 27, 2017): Thanks, didn't notice I'd left that in aha! Any idea what's causing the error?
Author
Owner

@stingrai24 commented on GitHub (Oct 27, 2017):

Never mind, found the error! It was to do with my terminal being configured to open a link once its pasted. If I typed the first part of the link then paste the rest, it doesn't recognise it as a link and everything works fine!

<!-- gh-comment-id:340053789 --> @stingrai24 commented on GitHub (Oct 27, 2017): Never mind, found the error! It was to do with my terminal being configured to open a link once its pasted. If I typed the first part of the link then paste the rest, it doesn't recognise it as a link and everything works fine!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#117
No description provided.