[GH-ISSUE #13] user_playlists_contents.py and user_starred_playlist.py examples failing #4

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

Originally created by @purplehat7 on GitHub (Jun 28, 2014).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/13

I tried StackOverflow first, as I thought this was more something I was doing wrong and less a problem with the code itself, but I was redirected here. Anyways, here's what I wrote at Stack Overflow:

I cloned and installed Paul Lamere's Python wrapper for the Spotify Web API via python setup.py install but I can't seem to run some of the examples correctly.

Specifically, when I try to run user_playlists_contents.py or user_starred_playlist.py, a browser is launched and I'm directed to the Spotify login page. After logging in, I get a Spotify error within the browser that only says: "Oops! Something went wrong." The script asks for the URL I was redirected to, but entering in both the URL of the login page and the URL of the error page (obviously) trigger an error within the Terminal: spotipy.oauth2.SpotifyOauthError: Bad Request

At first I was using a Facebook-connected Spotify account and logging in to Spotify through Facebook when prompted, so I thought that might be an issue. However even after creating a new email-only Spotify account and running the scripts on this new email-only username I got the same results.

I also tried registering a new App in my Spotify developer account and using its CLIENT_ID, CLIENT_SECRET, and REDIRECT_URI in the examples/util.py but this didn't seem to do anything. It seems unlikely anyways that modifying examples/util.py is necessary.

Thinking this might be a browser issue I also reset my browser (Chrome) and after that didn't work I tried switching Safari to the default browser but that also did nothing.

Both these scripts depend on prompt_for_user_token() which is defined in examples/util.py, and seems to be where things are going wrong.

What am I doing wrong? Have I missed something painfully obvious? Thanks in advance.

Originally created by @purplehat7 on GitHub (Jun 28, 2014). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/13 [I tried StackOverflow first](http://stackoverflow.com/q/24462897/1402368), as I thought this was more something I was doing wrong and less a problem with the code itself, but I was redirected here. Anyways, here's what I wrote at Stack Overflow: > I cloned and installed Paul Lamere's [Python wrapper for the Spotify Web API](https://github.com/plamere/spotipy) via `python setup.py install` but I can't seem to run some of the examples correctly. > > Specifically, when I try to run [`user_playlists_contents.py`](https://github.com/plamere/spotipy/blob/master/examples/user_playlists_contents.py) or [`user_starred_playlist.py`](https://github.com/plamere/spotipy/blob/master/examples/user_starred_playlist.py), a browser is launched and I'm directed to the Spotify login page. After logging in, I get a Spotify error within the browser that only says: "Oops! Something went wrong." The script asks for the URL I was redirected to, but entering in both the URL of the login page and the URL of the error page (obviously) trigger an error within the Terminal: `spotipy.oauth2.SpotifyOauthError: Bad Request` > > At first I was using a Facebook-connected Spotify account and logging in to Spotify through Facebook when prompted, so I thought that might be an issue. However even after creating a new email-only Spotify account and running the scripts on this new email-only username I got the same results. > > I also tried registering a new App in my Spotify developer account and using its `CLIENT_ID`, `CLIENT_SECRET`, and `REDIRECT_URI` in the `examples/util.py` but this didn't seem to do anything. It seems unlikely anyways that modifying `examples/util.py` is necessary. > > Thinking this might be a browser issue I also reset my browser (Chrome) and after that didn't work I tried switching Safari to the default browser but that also did nothing. > > Both these scripts depend on `prompt_for_user_token()` which is defined in [`examples/util.py`](https://github.com/plamere/spotipy/blob/master/examples/util.py), and seems to be where things are going wrong. > > What am I doing wrong? Have I missed something painfully obvious? Thanks in advance.
kerem closed this issue 2026-02-27 23:20:21 +03:00
Author
Owner

@plamere commented on GitHub (Jul 1, 2014):

Hi acannon - how are you setting the CLIENT_ID, CLIENT_SECRET and REDIRECT_URI?

<!-- gh-comment-id:47642573 --> @plamere commented on GitHub (Jul 1, 2014): Hi acannon - how are you setting the CLIENT_ID, CLIENT_SECRET and REDIRECT_URI?
Author
Owner

@purplehat7 commented on GitHub (Jul 13, 2014):

I was setting them as global vars within the script as opposed to env vars. Oops. Thanks! Would setting these vars be worth adding to the quick start docs? Or is having to do this obvious to everyone else but me?

<!-- gh-comment-id:48831435 --> @purplehat7 commented on GitHub (Jul 13, 2014): I was setting them as global vars within the script as opposed to env vars. Oops. Thanks! Would setting these vars be worth adding to the quick start docs? Or is having to do this obvious to everyone else but me?
Author
Owner

@1337sup3rh4x0r commented on GitHub (Nov 25, 2014):

Can you maybe explain how to correctly set these variables?
I simply added the three lines into the python file below the import lines like this:
SPOTIPY_CLIENT_ID='xxx'
SPOTIPY_CLIENT_SECRET='yyy'
SPOTIPY_REDIRECT_URI='zzz'

and the script won't run, telling me
spotipy.client.SpotifyException: http status: 550, code:-1 - no credentials set

<!-- gh-comment-id:64316160 --> @1337sup3rh4x0r commented on GitHub (Nov 25, 2014): Can you maybe explain how to correctly set these variables? I simply added the three lines into the python file below the import lines like this: SPOTIPY_CLIENT_ID='xxx' SPOTIPY_CLIENT_SECRET='yyy' SPOTIPY_REDIRECT_URI='zzz' and the script won't run, telling me spotipy.client.SpotifyException: http status: 550, code:-1 - no credentials set
Author
Owner

@plamere commented on GitHub (Nov 25, 2014):

those should be set as environment variables. How you set them varies depenidng on what OS you are on. See https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=setting%20environment%20variables

<!-- gh-comment-id:64388325 --> @plamere commented on GitHub (Nov 25, 2014): those should be set as environment variables. How you set them varies depenidng on what OS you are on. See https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=setting%20environment%20variables
Author
Owner

@1337sup3rh4x0r commented on GitHub (Nov 27, 2014):

Ah ok now I get what is meant by that. Thank you :)

<!-- gh-comment-id:64778563 --> @1337sup3rh4x0r commented on GitHub (Nov 27, 2014): Ah ok now I get what is meant by that. Thank you :)
Author
Owner

@1337sup3rh4x0r commented on GitHub (Nov 28, 2014):

I am getting further along the login process now but at the point where the CLI output tells me to visit a link and enter the redirect url afterwards it fails. The link sends me to a page which returns "INVALID_CLIENT: Invalid redirect URI" and when I enter the redirect URL (www.google.com) anyway, the CLI returns "spotipy.oauth2.SpotifyOauthError: Bad Request"

Maybe I got this whole redirect thing wrong? What is it needed for? Do I need to host a site which implements some code to get authenticated?I basically just want to run a python script that outputs the contents of a playlist ...

I am aware that this might be a noob question but please tell me where I can get more info. Thanks for your support!

<!-- gh-comment-id:64858210 --> @1337sup3rh4x0r commented on GitHub (Nov 28, 2014): I am getting further along the login process now but at the point where the CLI output tells me to visit a link and enter the redirect url afterwards it fails. The link sends me to a page which returns "INVALID_CLIENT: Invalid redirect URI" and when I enter the redirect URL (www.google.com) anyway, the CLI returns "spotipy.oauth2.SpotifyOauthError: Bad Request" Maybe I got this whole redirect thing wrong? What is it needed for? Do I need to host a site which implements some code to get authenticated?I basically just want to run a python script that outputs the contents of a playlist ... I am aware that this might be a noob question but please tell me where I can get more info. Thanks for your support!
Author
Owner

@plamere commented on GitHub (Nov 28, 2014):

You need to make sure that the URL you have used for the SPOTIPY_REDIRECT_URI
variable exactly matches the URL you have specified in your REDIRECT_URI
section of your application. You set this at

https://developer.spotify.com/my-applications/#!/applications

On Fri, Nov 28, 2014 at 1:06 AM, Killer1337 notifications@github.com
wrote:

I am getting further along the login process now but at the point where
the CLI output tells me to visit a link and enter the redirect url
afterwards it fails. The link sends me to a page which returns
"INVALID_CLIENT: Invalid redirect URI" and when I enter the redirect URL (
www.google.com) anyway, the CLI returns
"spotipy.oauth2.SpotifyOauthError: Bad Request"

Maybe I got this whole redirect thing wrong? What is it needed for? Do I
need to host a site which implements some code to get authenticated?I
basically just want to run a python script that outputs the contents of a
playlist ...

I am aware that this might be a noob question but please tell me where I
can get more info. Thanks for your support!


Reply to this email directly or view it on GitHub
https://github.com/plamere/spotipy/issues/13#issuecomment-64858210.

<!-- gh-comment-id:64889835 --> @plamere commented on GitHub (Nov 28, 2014): You need to make sure that the URL you have used for the SPOTIPY_REDIRECT_URI variable exactly matches the URL you have specified in your REDIRECT_URI section of your application. You set this at https://developer.spotify.com/my-applications/#!/applications On Fri, Nov 28, 2014 at 1:06 AM, Killer1337 notifications@github.com wrote: > I am getting further along the login process now but at the point where > the CLI output tells me to visit a link and enter the redirect url > afterwards it fails. The link sends me to a page which returns > "INVALID_CLIENT: Invalid redirect URI" and when I enter the redirect URL ( > www.google.com) anyway, the CLI returns > "spotipy.oauth2.SpotifyOauthError: Bad Request" > > Maybe I got this whole redirect thing wrong? What is it needed for? Do I > need to host a site which implements some code to get authenticated?I > basically just want to run a python script that outputs the contents of a > playlist ... > > I am aware that this might be a noob question but please tell me where I > can get more info. Thanks for your support! > > — > Reply to this email directly or view it on GitHub > https://github.com/plamere/spotipy/issues/13#issuecomment-64858210.
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#4
No description provided.