[GH-ISSUE #80] Login Issue #36

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

Originally created by @Duncanswilson on GitHub (Jan 21, 2016).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/80

Hello,

Just up front this may all be my ignorance of this api, but I'm currently not able to be login.

I'm calling

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, 
                        client_id='my_id_here', 
                        client_secret='my_secret_here',
                        redirect_uri='https:\\www.google.com')

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

and the issue I am running into is that when I login my web browser opens and goes to Spotify's error page and when I enter that url I (obviously) run into this:

line 16, in <module>
    redirect_uri='https:\\www.google.com')
  File "/Users/duncanwilson/anaconda2/lib/python2.7/site-packages/spotipy/util.py", line 86, in prompt_for_user_token
    token_info = sp_oauth.get_access_token(code)
  File "/Users/duncanwilson/anaconda2/lib/python2.7/site-packages/spotipy/oauth2.py", line 210, in get_access_token
    raise SpotifyOauthError(response.reason)
spotipy.oauth2.SpotifyOauthError: Bad Request

I've learned that this error is caused by the user already being logged in; but as soon as I logout then the redirect breaks when I attempt to login....

Thanks in advance! :)

Originally created by @Duncanswilson on GitHub (Jan 21, 2016). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/80 Hello, Just up front this may all be my ignorance of this api, but I'm currently not able to be login. I'm calling ``` 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, client_id='my_id_here', client_secret='my_secret_here', redirect_uri='https:\\www.google.com') 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 ``` and the issue I am running into is that when I login my web browser opens and goes to Spotify's error page and when I enter that url I (obviously) run into this: ``` line 16, in <module> redirect_uri='https:\\www.google.com') File "/Users/duncanwilson/anaconda2/lib/python2.7/site-packages/spotipy/util.py", line 86, in prompt_for_user_token token_info = sp_oauth.get_access_token(code) File "/Users/duncanwilson/anaconda2/lib/python2.7/site-packages/spotipy/oauth2.py", line 210, in get_access_token raise SpotifyOauthError(response.reason) spotipy.oauth2.SpotifyOauthError: Bad Request ``` I've learned that this error is caused by the user already being logged in; but as soon as I logout then the redirect breaks when I attempt to login.... Thanks in advance! :)
kerem closed this issue 2026-02-27 23:20:31 +03:00
Author
Owner

@joohoi commented on GitHub (Jan 22, 2016):

You might want to change your redirect_uri backslashes to actual forward slashes

https:\www.google.com to https://www.google.com

<!-- gh-comment-id:173836772 --> @joohoi commented on GitHub (Jan 22, 2016): You might want to change your redirect_uri backslashes to actual forward slashes https:\\www.google.com to https://www.google.com
Author
Owner

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

Yes check the redirect_uri is correct

<!-- gh-comment-id:570077399 --> @stephanebruckert commented on GitHub (Jan 1, 2020): Yes check the `redirect_uri` is correct
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#36
No description provided.