- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page