Type in your question below and we'll check to see what answers we can find...
Loading article...
Submitting...
If you couldn't find any answers in the previous step then we need to post your question in the community and wait for someone to respond. You'll be notified when that happens.
Simply add some detail to your question and refine the title if needed, choose the relevant category, then post.
Before we can post your question we need you to quickly make an account (or sign in if you already have one).
Don't worry - it's quick and painless! Just click below, and once you're logged in we'll bring you right back here and post your question. We'll remember what you've already typed in so you won't have to do it again.
Please see below the most popular frequently asked questions.
Loading article...
Loading faqs...
Please see below the current ongoing issues which are under investigation.
Loading issue...
Loading ongoing issues...
Running into an issue with my flask application. When not running my app inside of a docker container, I'm able to successfully authorize via Spotify API.
1. User navigates to localhost:5000/login
2. Spotify authorization agreement is displayed
3. User clicks "Agree"
4. User is routed to localhost:5000/callback where the text "Success" is displayed
But, when I dockerize the flask app, I get the following error in the browser when the user clicks "Agree" on the authorize page:
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
On the backend, here's the error i'm getting in the logs
{'error': 'invalid_client', 'error_description': 'Invalid client'}
Below is my Dockerfile, and app.py file
Dockerfile
FROM python:3.9-slim-buster
WORKDIR /app
COPY ./requirements.txt /app
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
ENV FLASK_APP=app.py
CMD ["flask", "run", "--host", "0.0.0.0"]
app.py
from flask import Flask, render_template, flash, session, redirect, request, Response, session, make_response
from spotify_connector import SpotifyConnector
connector = SpotifyConnector()
@app.route('/')
def index():
return "INDEX"
@app.route('/login')
def login():
client_id = app.config['CLIENT_ID']
redirect_uri = app.config['REDIRECT_URI']
scope = app.config['SCOPE']
authorize_url = 'https://accounts.spotify.com/en/authorize?'
state_key = connector.create_state_key(15)
session['state_key'] = state_key
parameters = 'response_type=code&client_id=' + client_id + '&redirect_uri=' + redirect_uri + '&scope=' + scope + '&state=' + state_key
response = make_response(redirect(authorize_url + parameters))
return response
@app.route('/callback')
def callback():
code = request.args.get('code', None)
state = request.args.get('state', None)
session.pop('state_key', None)
payload = connector.getToken(code)
if payload is not None:
session['access_token'] = payload['access_token']
session['refresh_token'] = payload['refresh_token']
return "SUCCESS"
else:
return "FAILURE"
if __name__ == "__main__":
app.run(host="localhost")
Solved! Go to Solution.
In the part of my code that generates the token for Spotify (where the error was originating), I was retrieving my client id and secret by using:
CLIENT_ID = os.getenv("CLIENT_ID")
CLIENT_SECRET = os.getenv("CLIENT_SECRET")
I threw in a print stament, and saw that Authorization header looked like this --Authorization: Basic "":"" , when it should look like this Authorization: Basic CLIENT_ID:CLIENT_SECRET. This confirmed that CLIENT_ID and CLIENT_SECRET weren't available.
I added the following to my Dockerfile, and I'm now able to successfully authorize:
ENV CLIENT_ID=*****
ENV CLIENT_SECRET=*****
Going further, I'm most likely going to get rid of the above two ENV declarations, and add the os.getenv declarations to my flask app config file.
Did you add the adress:port of the docker container to the callback URIs at the dashboard of your app?
CMD ["flask", "run", "--host", "0.0.0.0"] ?
In the part of my code that generates the token for Spotify (where the error was originating), I was retrieving my client id and secret by using:
CLIENT_ID = os.getenv("CLIENT_ID")
CLIENT_SECRET = os.getenv("CLIENT_SECRET")
I threw in a print stament, and saw that Authorization header looked like this --Authorization: Basic "":"" , when it should look like this Authorization: Basic CLIENT_ID:CLIENT_SECRET. This confirmed that CLIENT_ID and CLIENT_SECRET weren't available.
I added the following to my Dockerfile, and I'm now able to successfully authorize:
ENV CLIENT_ID=*****
ENV CLIENT_SECRET=*****
Going further, I'm most likely going to get rid of the above two ENV declarations, and add the os.getenv declarations to my flask app config file.
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…