Running into an issue where no requests from OAuth2Session object are being fulfilled.
curl GET "https://api.spotify.com/v1/me/top/artists" -H "Authorization: Bearer <access_token returned from OAuth2Session.access_token within failing program below>
works just fine.
The same session that returned that access token returns a 404 on:
session.get('/me/top/artists')
[expected, as Authorization: Bearer <access_token>
is not passed]
session.request('GET', '/me/top/artists')
[reading source seems to imply the Bearer Authorization header is included by default]
Larger code snippet [you'll notice it looks very similar to some of the examples]:
from flask import Flask, request, redirect, render_template, url_for
from rauth.service import OAuth2Service
from app import app
import os
spotify = OAuth2Service(name='spotify',
authorize_url=AUTH_URL,
access_token_url=TOKEN_URL,
client_id=os.getenv('SPOTIFY_CLIENT_ID'),
client_secret=os.getenv('SPOTIFY_CLIENT_SECRET'),
base_url='https://api.spotify.com/v1')
@app.route('/authorize')
def authorize():
redirect_uri = url_for('authorized', _external=True)
params = {'response_type': 'code', 'redirect_uri': redirect_uri, 'scope': 'user-top-read'}
return redirect(spotify.get_authorize_url(**params))
@app.route('/authorized')
def authorized():
if not 'code' in request.args:
flash('You did not authorize the request')
return redirect(url_for('welcome'))
redirect_uri = url_for('authorized', _external=True)
data = {'grant_type': 'authorization_code', 'code': request.args['code'], 'redirect_uri': redirect_uri}
def byte_decoder(byte_load):
return json.loads(byte_load.decode())
session = spotify.get_auth_session(data=data, decoder=byte_decoder)
# this is where I am trying the requests
return redirect(url_for('web'))
AUTH_URL
and TOKEN_URL
replace links because I don't have 10 reputation to post > 2 links.