Announcements
From 28th September 2026, Community private messages will no longer be available. If you have any private messages you'd like to keep, please save or copy them using these steps before this date. Thank you.

Help Wizard

Step 1

NEXT STEP

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

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

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

Reply
0 Replies

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 5 years ago  in Social & Random