[GH-ISSUE #429] Valid bearer authentication required for spotify.search() #253

Closed
opened 2026-02-27 23:21:38 +03:00 by kerem · 10 comments
Owner

Originally created by @queengooborg on GitHub (Jan 23, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/429

Unfortunately it seems that the example on the readme for performing a search is no longer functioning. Whenever attempting to perform a search, the following error occurs:

spotipy.client.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/search?q=upc%3A628810398782&limit=10&offset=0&type=album:
 Only valid bearer authentication supported

This may possibly be a Spotify API thing, but I figured to open up an issue here just in case. I'm running the latest spotipy (2.7.1), however this appears to be an issue in earlier versions (such as 2.4.4) as well.

Originally created by @queengooborg on GitHub (Jan 23, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/429 Unfortunately it seems that the example on the readme for performing a search is no longer functioning. Whenever attempting to perform a search, the following error occurs: ```py spotipy.client.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/search?q=upc%3A628810398782&limit=10&offset=0&type=album: Only valid bearer authentication supported ``` This may possibly be a Spotify API thing, but I figured to open up an issue here just in case. I'm running the latest `spotipy` (2.7.1), however this appears to be an issue in earlier versions (such as 2.4.4) as well.
kerem closed this issue 2026-02-27 23:21:38 +03:00
Author
Owner

@stephanebruckert commented on GitHub (Jan 23, 2020):

Hi @vinyldarkscratch, there was an issue with the last merge (now reverted), can you please try again with the current version (either master or 2.7.1)?

<!-- gh-comment-id:577856646 --> @stephanebruckert commented on GitHub (Jan 23, 2020): Hi @vinyldarkscratch, there was an issue with the last merge (now reverted), can you please try again with the current version (either master or 2.7.1)?
Author
Owner

@queengooborg commented on GitHub (Jan 24, 2020):

I'm still experiencing this issue, sadly. I was already running the latest release (2.7.1) before, as I had upgraded from 2.4.4 to see if the latest release would fix the issue.

<!-- gh-comment-id:578095259 --> @queengooborg commented on GitHub (Jan 24, 2020): I'm still experiencing this issue, sadly. I was already running the latest release (2.7.1) before, as I had upgraded from 2.4.4 to see if the latest release would fix the issue.
Author
Owner

@stephanebruckert commented on GitHub (Jan 24, 2020):

Search works on my side, can you please share some code? Do you know if you get the same problem with other endpoints, for example sp.playlist(id)?

<!-- gh-comment-id:578107141 --> @stephanebruckert commented on GitHub (Jan 24, 2020): Search works on my side, can you please share some code? Do you know if you get the same problem with other endpoints, for example `sp.playlist(id)`?
Author
Owner

@queengooborg commented on GitHub (Jan 24, 2020):

Of course -- here's the code I'm using:

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
spotify=spotipy.Spotify(SpotifyClientCredentials(client_id='REDACTED',client_secret='REDACTED'))
upc='628810398782'
spotify.search(q="upc:%s" %upc, type="album")

I've double-checked to make sure that the client ID and client secret I'm using match. However it appears that I'm not able to access other endpoints either (running spotify.playlist('7xRVn4q3S4bsOc4G5x36Ci') results in the same error)...

<!-- gh-comment-id:578112551 --> @queengooborg commented on GitHub (Jan 24, 2020): Of course -- here's the code I'm using: ```py import spotipy from spotipy.oauth2 import SpotifyClientCredentials spotify=spotipy.Spotify(SpotifyClientCredentials(client_id='REDACTED',client_secret='REDACTED')) upc='628810398782' spotify.search(q="upc:%s" %upc, type="album") ``` I've double-checked to make sure that the client ID and client secret I'm using match. However it appears that I'm not able to access other endpoints either (running `spotify.playlist('7xRVn4q3S4bsOc4G5x36Ci')` results in the same error)...
Author
Owner

@stephanebruckert commented on GitHub (Jan 24, 2020):

I would just like to double-check, because I've seen that same error on the broken master yesterday. I'm thinking you are running that broken version somehow. Can you please do:

pip uninstall spotipy
pip install spotipy==2.7.1

and try again?

<!-- gh-comment-id:578113978 --> @stephanebruckert commented on GitHub (Jan 24, 2020): I would just like to double-check, because I've seen that same error on the broken master yesterday. I'm thinking you are running that broken version somehow. Can you please do: pip uninstall spotipy pip install spotipy==2.7.1 and try again?
Author
Owner

@queengooborg commented on GitHub (Jan 24, 2020):

Uninstalling and reinstalling the Pip package didn't seem to help, sadly. As an additional test, I also double-checked the results on my web server, without any luck. I also checked with the latest master (and uninstalled the pip version while I did just in case), but ended up with the same results...

<!-- gh-comment-id:578118047 --> @queengooborg commented on GitHub (Jan 24, 2020): Uninstalling and reinstalling the Pip package didn't seem to help, sadly. As an additional test, I also double-checked the results on my web server, without any luck. I also checked with the latest `master` (and uninstalled the pip version while I did just in case), but ended up with the same results...
Author
Owner

@queengooborg commented on GitHub (Jan 24, 2020):

I was just doing a little bit of digging around, and I may have found something interesting! I set spotify.trace and spotify.trace_out to True, and it appears that the bearer token isn't stringifying properly:

Request headers: {'Authorization': 'Bearer <spotipy.oauth2.SpotifyClientCredentials object at 0x102ad1b50>', 'Content-Type': 'application/json'}
Response headers: {'WWW-Authenticate': 'Bearer realm="spotify", error="invalid_request", error_description="Only valid bearer authentication supported"', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': 'Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context', 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS, PUT, DELETE, PATCH', 'Access-Control-Allow-Credentials': 'true', 'Access-Control-Max-Age': '604800', 'Content-Type': 'application/json', 'content-encoding': 'gzip', 'Date': 'Fri, 24 Jan 2020 12:55:46 GMT', 'Via': '1.1 google', 'Alt-Svc': 'clear', 'Transfer-Encoding': 'chunked'}

(If it helps, I'm running Python 3.7.6 by the way. I realize I forgot to mention that before, whoops!)

<!-- gh-comment-id:578120508 --> @queengooborg commented on GitHub (Jan 24, 2020): I was just doing a little bit of digging around, and I may have found something interesting! I set `spotify.trace` and `spotify.trace_out` to `True`, and it appears that the bearer token isn't stringifying properly: ``` Request headers: {'Authorization': 'Bearer <spotipy.oauth2.SpotifyClientCredentials object at 0x102ad1b50>', 'Content-Type': 'application/json'} Response headers: {'WWW-Authenticate': 'Bearer realm="spotify", error="invalid_request", error_description="Only valid bearer authentication supported"', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': 'Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context', 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS, PUT, DELETE, PATCH', 'Access-Control-Allow-Credentials': 'true', 'Access-Control-Max-Age': '604800', 'Content-Type': 'application/json', 'content-encoding': 'gzip', 'Date': 'Fri, 24 Jan 2020 12:55:46 GMT', 'Via': '1.1 google', 'Alt-Svc': 'clear', 'Transfer-Encoding': 'chunked'} ``` (If it helps, I'm running Python 3.7.6 by the way. I realize I forgot to mention that before, whoops!)
Author
Owner

@stephanebruckert commented on GitHub (Jan 24, 2020):

Thanks for that. Yeah it definitely looks like you are having the bug that was since then reverted.

As the token you are receiving a SpotifyClientCredentials (old code, incorrect & reverted) github.com/plamere/spotipy@87a72a060f/spotipy/util.py (L109)

instead of receiving a string (correct in 2.7.1 as well as very latest) github.com/plamere/spotipy@26db832e24/spotipy/util.py (L109)

I'm quite sure you have the incorrect version. Can you do pip show spotipy, then it should give you the path in which spotipy is installed. Please try to delete that folder and install spotipy again

<!-- gh-comment-id:578123413 --> @stephanebruckert commented on GitHub (Jan 24, 2020): Thanks for that. Yeah it definitely looks like you are having the bug that was since then reverted. As the token you are receiving a `SpotifyClientCredentials` (old code, incorrect & reverted) https://github.com/plamere/spotipy/blob/87a72a060fa82153f1995c9f9e563baf1aca3282/spotipy/util.py#L109 instead of receiving a string (correct in 2.7.1 as well as very latest) https://github.com/plamere/spotipy/blob/26db832e24637f91411bb92bb031b41c54676e6d/spotipy/util.py#L109 I'm quite sure you have the incorrect version. Can you do `pip show spotipy`, then it should give you the path in which spotipy is installed. Please try to delete that folder and install spotipy again
Author
Owner

@queengooborg commented on GitHub (Jan 24, 2020):

Ahhhhhh, I finally figured out what it was! And it had come down to my own stupidity. At some point, I had assumed that client_credentials_manager was the first kwarg, which is not actually the case. So, I was just putting in spotify = spotipy.Spotify(SpotifyClientCredentials(...)) assuming that it would work, when it reality it was setting it to the auth kwarg, thus it wasn't actually calling the get_access_token() function, and just stringifying the object (as per client.py, line 97).

Sorry for the hassle on this one! This certainly will serve as a reminder to check kwargs more carefully... 😅

<!-- gh-comment-id:578125043 --> @queengooborg commented on GitHub (Jan 24, 2020): Ahhhhhh, I finally figured out what it was! And it had come down to my own stupidity. At some point, I had assumed that `client_credentials_manager` was the first kwarg, which is not actually the case. So, I was just putting in `spotify = spotipy.Spotify(SpotifyClientCredentials(...))` assuming that it would work, when it reality it was setting it to the `auth` kwarg, thus it wasn't actually calling the `get_access_token()` function, and just stringifying the object (as per client.py, line 97). Sorry for the hassle on this one! This certainly will serve as a reminder to check kwargs more carefully... 😅
Author
Owner

@stephanebruckert commented on GitHub (Jan 24, 2020):

Oh, cool. What a coincidence that your error message was very close to the one I saw yesterday!

Glad you found the solution.

<!-- gh-comment-id:578125673 --> @stephanebruckert commented on GitHub (Jan 24, 2020): Oh, cool. What a coincidence that your error message was very close to the one I saw yesterday! Glad you found the solution.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#253
No description provided.