4

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.

Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125
acannon828
  • 528
  • 7
  • 22
  • 1
    I think you should report this as an issue in its GitHub project, instead of using StackOverflow. That will notify the project's maintainers and would be able to help you out better. – José M. Pérez Jun 28 '14 at 08:34
  • @JMPerez I could do that. I tried StackOverflow first though because I thought this was something I was doing wrong, not a bug with the project. – acannon828 Jun 28 '14 at 14:33

2 Answers2

3

prompt_for_user_token method looks as below:

def prompt_for_user_token(username, scope=None):
    ''' prompts the user to login if necessary and returns
        the user token suitable for use with the spotipy.Spotify 
        constructor
    '''

    client_id = os.getenv('CLIENT_ID', 'YOUR_CLIENT_ID')
    client_secret = os.getenv('CLIENT_SECRET', 'YOUR_CLIENT_SECRET')
    redirect_uri = os.getenv('REDIRECT_URI', 'YOUR_REDIRECT_URI')
    .
    .

which requires you to set CLIENT_ID, CLIENT_SECRET and REDIRECT_URI environment variables before executing the example. You get these values by creating an app at My Applications section of Spotify Developer Site

In Unix, you can set environment variables in the command line as follows:

export CLIENT_ID={yourclient}
export CLIENT_SECRET={yoursecret}
export REDIRECT_URI={your redirect uri}

Then you need to copy and paste the full url you were redirected to on browser to proceed.

Faruk Sahin
  • 8,406
  • 5
  • 28
  • 34
1

I have a similar problem and found at least a work around solution. See here. I got this to work by passing the client_id, client_secret, redirect_uri as agruments in util.prompt_for_user_token. I had to copy and paste the entire URL including code. I did not mess with util.py at all.

J0e3gan
  • 8,740
  • 10
  • 53
  • 80
Steve
  • 413
  • 2
  • 5
  • 17
  • Consider incorporating the key elements of the content to which you have linked so your answer stands on its own. – J0e3gan Oct 31 '15 at 22:27