[GH-ISSUE #251] Authorized requests not working #134

Closed
opened 2026-02-27 23:21:00 +03:00 by kerem · 6 comments
Owner

Originally created by @tatoosh on GitHub (Feb 9, 2018).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/251

I created CLIENT_ID and Client_Secret and set my export parameters and also set a redirect_url like the howto says

export SPOTIPY_REDIRECT_URI='http://localhost'

The i run the script

import sys
import spotipy
import spotipy.util as util

scope = 'user-library-read'

if len(sys.argv) > 1:
    username = sys.argv[1]
else:
    print "Usage: %s username" % (sys.argv[0],)
    sys.exit()

token = util.prompt_for_user_token(username, scope)

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

I followed the link from the console on my pc: Opened https://accounts.spotify.com/authorize?scope .....

My Errors:
Illegal redirect_uri
or
INVALID_CLIENT: Invalid redirect URI

What did i wrong ??

Thx, Tatoosh

Originally created by @tatoosh on GitHub (Feb 9, 2018). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/251 I created CLIENT_ID and Client_Secret and set my export parameters and also set a redirect_url like the howto says >export SPOTIPY_REDIRECT_URI='http://localhost' The i run the script ```python import sys import spotipy import spotipy.util as util scope = 'user-library-read' if len(sys.argv) > 1: username = sys.argv[1] else: print "Usage: %s username" % (sys.argv[0],) sys.exit() token = util.prompt_for_user_token(username, scope) 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 ``` I followed the link from the console on my pc: Opened https://accounts.spotify.com/authorize?scope ..... My Errors: **Illegal redirect_uri** or **INVALID_CLIENT: Invalid redirect URI** What did i wrong ?? Thx, Tatoosh
kerem closed this issue 2026-02-27 23:21:00 +03:00
Author
Owner

@tatoosh commented on GitHub (Feb 9, 2018):

i forgot the last slash from the export url:
export SPOTIPY_REDIRECT_URI='http://localhost:8888/callback/'
After inserting token i got a new error:


Traceback (most recent call last):
  File "o.py", line 13, in <module>
    token = util.prompt_for_user_token(username, scope)
  File "build/bdist.linux-armv7l/egg/spotipy/util.py", line 88, in prompt_for_user_token
  File "build/bdist.linux-armv7l/egg/spotipy/oauth2.py", line 217, in get_access_token
spotipy.oauth2.SpotifyOauthError: Bad Request
<!-- gh-comment-id:364449528 --> @tatoosh commented on GitHub (Feb 9, 2018): i forgot the last slash from the export url: export SPOTIPY_REDIRECT_URI='http://localhost:8888/callback/' After inserting token i got a new error: ``` Traceback (most recent call last): File "o.py", line 13, in <module> token = util.prompt_for_user_token(username, scope) File "build/bdist.linux-armv7l/egg/spotipy/util.py", line 88, in prompt_for_user_token File "build/bdist.linux-armv7l/egg/spotipy/oauth2.py", line 217, in get_access_token spotipy.oauth2.SpotifyOauthError: Bad Request ```
Author
Owner

@tatoosh commented on GitHub (Feb 9, 2018):

Everything is working now through searching here. there was a typing bug in the docu.

<!-- gh-comment-id:364454411 --> @tatoosh commented on GitHub (Feb 9, 2018): Everything is working now through searching here. there was a typing bug in the docu.
Author
Owner

@xanpj commented on GitHub (Mar 18, 2019):

thanks your thread helped me.
For all users new to this:

  1. make this your redirect URI: SPOTIPY_REDIRECT_URI='http://localhost:8888/callback/'
  2. and add it to your redirect uri whitelist in spotify > app > edit settings > white list
<!-- gh-comment-id:473834797 --> @xanpj commented on GitHub (Mar 18, 2019): thanks your thread helped me. For all users new to this: 1) make this your redirect URI: SPOTIPY_REDIRECT_URI='http://localhost:8888/callback/' 2) and add it to your redirect uri whitelist in spotify > app > edit settings > white list
Author
Owner

@antoncoding commented on GitHub (Apr 11, 2019):

Everything is working now through searching here. there was a typing bug in the docu.

What is the typo? I'm facing the same issue..

<!-- gh-comment-id:482091711 --> @antoncoding commented on GitHub (Apr 11, 2019): > Everything is working now through searching here. there was a typing bug in the docu. What is the typo? I'm facing the same issue..
Author
Owner

@aleksei-tro commented on GitHub (Jul 4, 2019):

Everything is working now through searching here. there was a typing bug in the docu.

What is the typo? I'm facing the same issue..

Same here. Can anyone help?

<!-- gh-comment-id:508382669 --> @aleksei-tro commented on GitHub (Jul 4, 2019): > > Everything is working now through searching here. there was a typing bug in the docu. > > What is the typo? I'm facing the same issue.. Same here. Can anyone help?
Author
Owner

@stephanebruckert commented on GitHub (Jan 13, 2020):

3 things to check for this problem https://github.com/plamere/spotipy/issues/402#issuecomment-573890067

<!-- gh-comment-id:573892522 --> @stephanebruckert commented on GitHub (Jan 13, 2020): 3 things to check for this problem https://github.com/plamere/spotipy/issues/402#issuecomment-573890067
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#134
No description provided.