Spotipy Error Examples (Spotify Web API Python)

I cloned and installed the Paul Lamere Python shell for the Spotify Web API through python setup.py install, but I cannot run some of the examples correctly.

In particular, when I try to launch user_playlists_contents.pyor user_starred_playlist.py, the browser launches, and I head to the Spotify login page. After logging in, I get a Spotify error in the browser, which only says: "Oh, something went wrong." The script asks for the URL that I was redirected to, but enter the URL of the login page and the URL of the error page (obviously) to cause the error in the terminal:spotipy.oauth2.SpotifyOauthError: Bad Request

At first I used a Spotify account connected to Facebook and logged in to Spotify via Facebook when prompted, so I thought this might be a problem. However, even after creating a new Spotify account for email only and running scripts on this new username via email, I got the same results.

I also tried registering the new application in my Spotify developer account and using it CLIENT_ID, CLIENT_SECRETand REDIRECT_URIin examples/util.py, but that didn't seem to do anything. It seems unlikely that change is examples/util.pynecessary.

I think this may be a problem with the browser. I also reset my browser (Chrome), and after that did not work. I tried switching Safari to the default browser, but that didn't do anything either.

Both of these scenarios depend on prompt_for_user_token()which is defined in examples/util.py, and everything seems to be going wrong.

What am I doing wrong? Did I miss something painfully obvious? Thanks in advance.

+4
source share
2 answers

prompt_for_user_token the method is as follows:

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 that the environment variables CLIENT_ID, CLIENT_SECRET, and REDIRECT_URI be set before executing the example. You get these values โ€‹โ€‹by creating an application in My Applications Spotify Developer Site

On Unix, you can set environment variables on 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 to which you were redirected to the browser to continue.

+3

, , . . . , client_id, client_secret, redirect_uri agruments util.prompt_for_user_token. URL, . util.py.

+1

Source: https://habr.com/ru/post/1546386/


All Articles