Day 093 - Project 93 : What's your top ten?

Same. Am able to get authorized but actually getting a search query to work is a different story.

Thanks @HarshalSeth @JustinUplinger @Raschoe for your comments.

We are revisiting the 100 Days of Code tasks at the moment to check + tidy up. I’ll make sure to update Day 93 with the most recent information as soon as possible.


All good, thanks so much! Yeah Spotify just changed their documentation so it’s a little confusing. Will try to figure it out in the meantime and post if I can figure it out

1 Like

Got it to work. Found that…

The lesson was missing the line data = response.json() before trying to print out the response data. It is in the solution though.

Some info on how the queries are formatted would be helpful, like explaining that ‘%20’ means a space in a URL etc. so it’s easier to understand the example query given.

This worked for me, with {inputYear} being the variable for year pulled from the form:

search = f"?q=year:{inputYear}&type=track&market=US&limit=10&offset=5&include_external=audio"

I don´t understand it, where can I put in the access token in spotify?

Can anyone tell me why this code doesn’t work?

when you open it in a new tab and add /boom to the end. It says method not allowed

Cause you only set the method to POST

@app.route("/boom", methods=["POST"])

change that to methods=["GET"] (or you can just remove the methods kwarg entirely cause the method defaults to GET)

1 Like

Thank you so much for trying to help I really appreciate it because this has been keeping me up at night, I really thank you. But when I remove the methods kwarg and I go to the site it says “bad request”

Oh sorry, didn’t realize, but basically, you run the app before creating the / route. So you need to move the to after you define the / route.

1 Like

it still says “bad request” :sob:

Okay hopefully this is the last error lol

Basically, you’re not returning the page after defining the variable. No idea how I missed this earlier.

1 Like

It still says bad request, should @DavidAtReplit get involved?

@DavidAtReplit pls help you’re the only hope!!!

I get my “access_token” correctly (I’ve checked it in the previous step by step), but when I copy and paste this code of David and I enter any band as a query it says:

Artist: Nirvana
“grant_type”: “client_credentials”
Traceback (most recent call last):
File “”, line 26, in
for track in data[“tracks”][“items”]:
KeyError: ‘tracks’

I’m lost. Please S.O.S.

p.s. the code of David here:

import requests, json, os # Missing import
from requests.auth import HTTPBasicAuth

clientID = os.environ['CLIENT_ID']
clientSecret = os.environ['CLIENT_SECRET']

url = ""
data = {"grant_type":"client_credentials"}
auth = HTTPBasicAuth(clientID, clientSecret)

response =, data=data, auth=auth)
accessToken = response.json()["access_token"]

artist = input("Artist: ").lower() # Variable identifier typo
artist = artist.replace(" ", "%20")

url = ""
headers = {'Authorization': f'Bearer {accessToken}'}
search = f"?q=artist%3A{artist}&type=track&limit=5" # Missing 'q' in the URL - yes, this will break the code! Any incorrect URL will

fullURL = f"{url}{search}"

response = requests.get(fullURL, headers=headers)
print(json.dumps(data, indent=2))  

for track in data["tracks"]["items"]:

:boom:*** UPDATE / SOLUTION ** :boom:

as @JustinUplinger said, data = response.json() is missing right after the line 23 of the code I have just pasted above.
@DavidAtReplit , @QwertyQwerty88 , bruhs, that is missing! It was giving me hell! Fix it before someone else’s head collapses!

So I was going to post a question here but I managed to solve my problem before posting so I’d like to help people working through this day’s challenge with what I discovered. As other people have mentioned, it seems like Spotify changed the way in which you use the OAuth Token Auth section, but we don’t need to do what David does in the video where he plugs in the token to the website to experiment with the search query (I still don’t know how to do that, honestly). If you know how the syntax of the query works in the URL, that will be enough. The code below has a single error and fixing it would’ve prevented me from going down the rabbit hole of trying to figure out extra non-existent authorization steps to pull a successful query. Anyways, there needs to be a space between Bearer and {accessToken}.

import json
import requests, os
from requests.auth import HTTPBasicAuth ## attaches basic authentication to the given request object

clientId = os.environ['CLIENT_ID'] ## "username"
clientSecret = os.environ['CLIENT_SECRET'] ## "password"

url = "" ## where to get the token
data = {"grant_type": "client_credentials"} ## what to get
auth = HTTPBasicAuth(clientId, clientSecret) ## authentifies my permission to send the request

response =, data = data, auth = auth) ## stores the response

## print(response.ok) ## check if the call is working
## print(response.json())
## print(response.status_code)

accessToken = response.json()["access_token"] ## grab the token

url = ""
headers = {"Authorization": f"Bearer{accessToken}"}
search = "?q=artist%3Aknowmads&type=track&limit=10"

fullURL = f"{url}{search}"

response = requests.get(fullURL, headers=headers)
data = response.json()

print(json.dumps(data, indent=2))

Can anyone please link a repl with David’s full solution? His repl linked on the video doesn’t work.