Authorization Code Flow: 500 Internal Server Error at initial step of authorization

Reply
Highlighted

Authorization Code Flow: 500 Internal Server Error at initial step of authorization

Newbie

Let me preface this by saying I am new to working with APIs and making requests.

 

I am running a website with via flask on an AWS EC2 instance with ubuntu 20.04 (not sure if this will help but just to give as much info as possible). So far I have been following the Authorization Code Flow guide on github, but I have been having some trouble. 

 

Here is a snippet of my app.py file for the flask app:

 

CLIENT_ID = credentials.clientid
SPOTIFY_AUTH_URL = "https://accounts.spotify.com/authorize"
CLIENT_SIDE_URL = "http://www.drewmi.ch"
PORT = 80
REDIRECT_URI = "{}:{}/redirect".format(CLIENT_SIDE_URL, PORT)
SCOPE = "playlist-modify-private"
STATE = ""

@app.route("/")
def home_function():
    return render_template("home.html")



@app.route("/spotify")
def spotify():
    payload = {
        'client_id': CLIENT_ID,
        'response_type': 'code',
        'redirect_uri': REDIRECT_URI,
        'state' : STATE,
        'scope': SCOPE,
    }

    res = make_response(redirect(f'{SPOTIFY_AUTH_URL}/?{urlencode(payload)}'))
    return res

@app.route("/redirect")
def redirect():
    startup.getUserToken(request.args['code'])
    return render_template("redirect.html")

 

When I navigate to the /spotify page on my website, I don't even make it to the spotify login prompt. I get a 500 Internal Server Error. On the spotify dashboard I have my redirect URI set to "http://www.drewmi.ch/redirect", I've found many people have made the mistake there, but I don't think that's the case here.

 

The flow I'm aiming to have is /spotify -> login -> /redirect -> ...

 

Thank you,

Drew

SUGGESTED POSTS