[GH-ISSUE #230] Bad Request when trying to get Authorized #120

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

Originally created by @gawaineo on GitHub (Nov 9, 2017).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/230

Opened https://accounts.spotify.com/authorize?scope=user-library-read+user-modify-playback-state+user-read-currently-playing+user-read-playback-state+user-read-recently-played&redirect_uri=http%3A%2F%2F0.0.0.0%3A5000%2Fcallback&response_type=code&client_id=6a73223799534df0ae6e0547c0324255 in your browser


Enter the URL you were redirected to: Using PPAPI flash.
--disable-new-tab-first-run --enable-user-scripts --ppapi-flash-path=/usr/lib/adobe-flashplugin/libpepflashplayer.so --ppapi-flash-version=
Created new window in existing browser session.
p7dftiRNE44fYVHrvXAT3YoXU35xrhCOipuz5mVFU7LGcfVzdQinao4l9BGcqFLry2el85tG6mTA3hAib4R_gq_vnNNnw6L8pyfrw6SbLMzy3BCfyd9dRi_b_0yYNNxH1zVP3KdKUcPKQTo_ooUiufb0UgnvJOFwSrXSp


Traceback (most recent call last):
  File "spot.py", line 11, in <module>
    redirect_uri=settings.REDIRECT_URI)
  File "/home/gawaine/workspace/git/v2/local/lib/python2.7/site-packages/spotipy/util.py", line 86, in prompt_for_user_token
    token_info = sp_oauth.get_access_token(code)
  File "/home/gawaine/workspace/git/v2/local/lib/python2.7/site-packages/spotipy/oauth2.py", line 217, in get_access_token
    raise SpotifyOauthError(response.reason)
spotipy.oauth2.SpotifyOauthError: Bad Request

This happens when I use the util.prompt_for_user_token() function with client_id, client_secret etc and then try to paste the redirect URL with the code into the terminal.

Originally created by @gawaineo on GitHub (Nov 9, 2017). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/230 ``` Opened https://accounts.spotify.com/authorize?scope=user-library-read+user-modify-playback-state+user-read-currently-playing+user-read-playback-state+user-read-recently-played&redirect_uri=http%3A%2F%2F0.0.0.0%3A5000%2Fcallback&response_type=code&client_id=6a73223799534df0ae6e0547c0324255 in your browser Enter the URL you were redirected to: Using PPAPI flash. --disable-new-tab-first-run --enable-user-scripts --ppapi-flash-path=/usr/lib/adobe-flashplugin/libpepflashplayer.so --ppapi-flash-version= Created new window in existing browser session. p7dftiRNE44fYVHrvXAT3YoXU35xrhCOipuz5mVFU7LGcfVzdQinao4l9BGcqFLry2el85tG6mTA3hAib4R_gq_vnNNnw6L8pyfrw6SbLMzy3BCfyd9dRi_b_0yYNNxH1zVP3KdKUcPKQTo_ooUiufb0UgnvJOFwSrXSp Traceback (most recent call last): File "spot.py", line 11, in <module> redirect_uri=settings.REDIRECT_URI) File "/home/gawaine/workspace/git/v2/local/lib/python2.7/site-packages/spotipy/util.py", line 86, in prompt_for_user_token token_info = sp_oauth.get_access_token(code) File "/home/gawaine/workspace/git/v2/local/lib/python2.7/site-packages/spotipy/oauth2.py", line 217, in get_access_token raise SpotifyOauthError(response.reason) spotipy.oauth2.SpotifyOauthError: Bad Request ``` This happens when I use the `util.prompt_for_user_token()` function with client_id, client_secret etc and then try to paste the redirect URL with the code into the terminal.
kerem closed this issue 2026-02-27 23:20:55 +03:00
Author
Owner

@Hurstwood commented on GitHub (Nov 14, 2017):

The typo in the documentation might be tripping you up. Look at my post #232 - it might help you.

<!-- gh-comment-id:344144446 --> @Hurstwood commented on GitHub (Nov 14, 2017): The typo in the documentation might be tripping you up. Look at my post #232 - it might help you.
Author
Owner

@Loewkie commented on GitHub (Dec 21, 2017):

I'm also having this issue:

import spotipy
import spotipy.util as util

username = 'username_of_my_account' #placeholder value here
client_id = 'ID' #placeholder value here
client_secret = 'SECRET' #placeholder value here
redirect_uri = 'http://localhost:8888/callback/'

token = util.prompt_for_user_token(username, client_id, client_secret, redirect_uri)

I have checked a trillion times to make sure that the redirect_uri is exactly the same in my code and in my whitelisted uri's. When it wasn't in my whitelisted uri's yet I got Invalid URI, now I'm getting Illegal URI

<!-- gh-comment-id:353485277 --> @Loewkie commented on GitHub (Dec 21, 2017): I'm also having this issue: import spotipy import spotipy.util as util username = 'username_of_my_account' #placeholder value here client_id = 'ID' #placeholder value here client_secret = 'SECRET' #placeholder value here redirect_uri = 'http://localhost:8888/callback/' token = util.prompt_for_user_token(username, client_id, client_secret, redirect_uri) I have checked a trillion times to make sure that the redirect_uri is exactly the same in my code and in my whitelisted uri's. When it wasn't in my whitelisted uri's yet I got _Invalid URI_, now I'm getting _Illegal URI_
Author
Owner

@ritiek commented on GitHub (Dec 22, 2017):

@Loewkie Notice the order of parameters in util.prompt_for_user_token():

github.com/plamere/spotipy@4c2c1d763a/spotipy/util.py (L9-L10)

In your example, you are providing client_id instead of scope and so on..

You should use something like:

token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri)

If you're not familiar with scopes, check out these official docs.

For example, if you want read access to your private playlists. Your scope should be:

scope = 'playlist-read-private'

Note: You can gain additional information using scopes only for the user whose client_id and client_secret you used.

<!-- gh-comment-id:353616116 --> @ritiek commented on GitHub (Dec 22, 2017): @Loewkie Notice the order of parameters in `util.prompt_for_user_token()`: https://github.com/plamere/spotipy/blob/4c2c1d763a3653aa225c4af848409ec31286a6bf/spotipy/util.py#L9-L10 In your example, you are providing client_id instead of scope and so on.. You should use something like: ``` token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri) ``` If you're not familiar with scopes, check out these [official docs](https://developer.spotify.com/web-api/using-scopes/). For example, if you want read access to your private playlists. Your scope should be: ``` scope = 'playlist-read-private' ``` **Note:** You can gain additional information using scopes only for the user whose client_id and client_secret you used.
Author
Owner

@Loewkie commented on GitHub (Dec 22, 2017):

OK that solved it for me at least. Thank you. Silly that it was something this simple really.

<!-- gh-comment-id:353624298 --> @Loewkie commented on GitHub (Dec 22, 2017): OK that solved it for me at least. Thank you. Silly that it was something this simple really.
Author
Owner

@seeess1 commented on GitHub (Nov 7, 2020):

I'm having related problems. Just trying to get off the ground with Spotipy by retrieving data from my personal account but running into authentication errors. Following this example and setting environmental variables for the client ID, secret, and redirect URI but getting this error:

"OSError: [Errno 48] Address already in use"

I'm currently using "http://localhost:8888/callback/" as my redirect URI. Not sure if that might be causing problems.

Any ideas here?

<!-- gh-comment-id:723373608 --> @seeess1 commented on GitHub (Nov 7, 2020): I'm having related problems. Just trying to get off the ground with Spotipy by retrieving data from my personal account but running into authentication errors. Following [this example](https://github.com/plamere/spotipy/blob/master/examples/my_playlists.py) and setting environmental variables for the client ID, secret, and redirect URI but getting this error: "OSError: [Errno 48] Address already in use" I'm currently using "http://localhost:8888/callback/" as my redirect URI. Not sure if that might be causing problems. Any ideas here?
Author
Owner

@dpnem commented on GitHub (Nov 8, 2020):

I switched to using "http://www.google.com/" which solved that particular issue for me.

<!-- gh-comment-id:723567419 --> @dpnem commented on GitHub (Nov 8, 2020): I switched to using "http://www.google.com/" which solved that particular issue for me.
Author
Owner

@Peter-Schorn commented on GitHub (Nov 10, 2020):

@seeess1 "OSError: [Errno 48] Address already in use" means that there is another process already using port 8888. You need to find it and kill it. Alternatively, use a different port. See https://stackoverflow.com/a/39557155/12394554

<!-- gh-comment-id:724990171 --> @Peter-Schorn commented on GitHub (Nov 10, 2020): @seeess1 "OSError: [Errno 48] Address already in use" means that there is another process already using port 8888. You need to find it and kill it. Alternatively, use a different port. See https://stackoverflow.com/a/39557155/12394554
Author
Owner

@seeess1 commented on GitHub (Nov 10, 2020):

Thank you very much for the reply. An alternative suggestion was given to me, which was to essentially ignore the error messages that appear in the browser, copy the URL that appears, and paste that URL into the cell in my Jupyter Notebook. That worked and I'm now able to retrieve my personal data from the API. Not sure if that's how it's supposed to work but it did nonetheless.

<!-- gh-comment-id:724996982 --> @seeess1 commented on GitHub (Nov 10, 2020): Thank you very much for the reply. An alternative suggestion was given to me, which was to essentially ignore the error messages that appear in the browser, copy the URL that appears, and paste that URL into the cell in my Jupyter Notebook. That worked and I'm now able to retrieve my personal data from the API. Not sure if that's how it's supposed to work but it did nonetheless.
Author
Owner

@Peter-Schorn commented on GitHub (Nov 10, 2020):

Thank you very much for the reply. An alternative suggestion was given to me, which was to essentially ignore the error messages that appear in the browser, copy the URL that appears, and paste that URL into the cell in my Jupyter Notebook. That worked and I'm now able to retrieve my personal data from the API. Not sure if that's how it's supposed to work but it did nonetheless.

Yes, you can ignore the actual content of the page that you are redirected to. All that matters is the URL itself. If you look at the query string of the URL, you will see a code parameter. That's what spotipy needs to complete the authorization process.

<!-- gh-comment-id:725007486 --> @Peter-Schorn commented on GitHub (Nov 10, 2020): > Thank you very much for the reply. An alternative suggestion was given to me, which was to essentially ignore the error messages that appear in the browser, copy the URL that appears, and paste that URL into the cell in my Jupyter Notebook. That worked and I'm now able to retrieve my personal data from the API. Not sure if that's how it's supposed to work but it did nonetheless. Yes, you can ignore the actual content of the page that you are redirected to. All that matters is the URL itself. If you look at the query string of the URL, you will see a `code` parameter. That's what spotipy needs to complete the authorization process.
Author
Owner

@seeess1 commented on GitHub (Nov 10, 2020):

Awesome thank you. Much appreciated.

<!-- gh-comment-id:725031222 --> @seeess1 commented on GitHub (Nov 10, 2020): Awesome thank you. Much appreciated.
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#120
No description provided.