[GH-ISSUE #687] Error Only valid bearer authentication supported, reason: None?? #408

Open
opened 2026-02-27 23:22:27 +03:00 by kerem · 4 comments
Owner

Originally created by @phantom2152 on GitHub (Jun 7, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/687

Hey I was getting info about a single track while I got this error

my code is

from spotipy import oauth2,spotify
re=oauth2.SpotifyClientCredentials(client_id=id,client_secret=sec).get_access_token()
spo = Spotify(re)
url = spo.track("https://open.spotify.com/track/3fHNjvF6AU1LXVez0wnFvw")
print(url)

And I am getting following error

HTTP Error for GET to https://api.spotify.com/v1/tracks/3fHNjvF6AU1LXVez0wnFvw returned 400 due to Only valid bearer authentication supported
Traceback (most recent call last):
  File "/home/anishgowda/.local/lib/python3.8/site-packages/spotipy/client.py", line 245, in _internal_call
    response.raise_for_status()
  File "/home/anishgowda/.local/lib/python3.8/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/tracks/3fHNjvF6AU1LXVez0wnFvw

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/anishgowda/.local/lib/python3.8/site-packages/spotipy/client.py", line 339, in track
    return self._get("tracks/" + trid, market=market)
  File "/home/anishgowda/.local/lib/python3.8/site-packages/spotipy/client.py", line 291, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/home/anishgowda/.local/lib/python3.8/site-packages/spotipy/client.py", line 261, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/tracks/3fHNjvF6AU1LXVez0wnFvw:
 Only valid bearer authentication supported, reason: None



Originally created by @phantom2152 on GitHub (Jun 7, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/687 <!--- Please make sure you've: - read the FAQ https://github.com/plamere/spotipy/blob/master/FAQ.md - read the documentation https://spotipy.readthedocs.io/en/latest/ - searched older issues If your question is about code, please share the code you are using ---> Hey I was getting info about a single track while I got this error my code is ``` from spotipy import oauth2,spotify re=oauth2.SpotifyClientCredentials(client_id=id,client_secret=sec).get_access_token() spo = Spotify(re) url = spo.track("https://open.spotify.com/track/3fHNjvF6AU1LXVez0wnFvw") print(url) ``` And I am getting following error ``` HTTP Error for GET to https://api.spotify.com/v1/tracks/3fHNjvF6AU1LXVez0wnFvw returned 400 due to Only valid bearer authentication supported Traceback (most recent call last): File "/home/anishgowda/.local/lib/python3.8/site-packages/spotipy/client.py", line 245, in _internal_call response.raise_for_status() File "/home/anishgowda/.local/lib/python3.8/site-packages/requests/models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/tracks/3fHNjvF6AU1LXVez0wnFvw During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/anishgowda/.local/lib/python3.8/site-packages/spotipy/client.py", line 339, in track return self._get("tracks/" + trid, market=market) File "/home/anishgowda/.local/lib/python3.8/site-packages/spotipy/client.py", line 291, in _get return self._internal_call("GET", url, payload, kwargs) File "/home/anishgowda/.local/lib/python3.8/site-packages/spotipy/client.py", line 261, in _internal_call raise SpotifyException( spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/tracks/3fHNjvF6AU1LXVez0wnFvw: Only valid bearer authentication supported, reason: None ```
Author
Owner

@Peter-Schorn commented on GitHub (Jun 7, 2021):

Read the documentation: https://spotipy.readthedocs.io/en/2.18.0/#client-credentials-flow

<!-- gh-comment-id:856080396 --> @Peter-Schorn commented on GitHub (Jun 7, 2021): Read the documentation: https://spotipy.readthedocs.io/en/2.18.0/#client-credentials-flow
Author
Owner

@spyvanilla commented on GitHub (May 10, 2022):

The .get_access_token() method returns a JSON object, to get the acess_token inside the object, you have to do this:

spo = Spotify(auth=re['access_token'])
<!-- gh-comment-id:1122611014 --> @spyvanilla commented on GitHub (May 10, 2022): The ```.get_access_token()``` method returns a JSON object, to get the ```acess_token``` inside the object, you have to do this: ```python spo = Spotify(auth=re['access_token']) ```
Author
Owner

@Peter-Schorn commented on GitHub (May 10, 2022):

spo = Spotify(auth=re['access_token'])

While this works, it is not recommended because the access token will not be automatically refreshed when it expires after an hour. As shown in the README, this is how you should initialize Spotify:

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="YOUR_APP_CLIENT_ID",
                                               client_secret="YOUR_APP_CLIENT_SECRET",
                                               redirect_uri="YOUR_APP_REDIRECT_URI",
                                               scope="user-library-read"))
<!-- gh-comment-id:1122902136 --> @Peter-Schorn commented on GitHub (May 10, 2022): > ``` > spo = Spotify(auth=re['access_token']) > ``` While this works, it is not recommended because the access token will not be automatically refreshed when it expires after an hour. As shown in the README, this is how you should initialize `Spotify`: ``` sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="YOUR_APP_CLIENT_ID", client_secret="YOUR_APP_CLIENT_SECRET", redirect_uri="YOUR_APP_REDIRECT_URI", scope="user-library-read")) ```
Author
Owner

@stephanebruckert commented on GitHub (Jun 18, 2022):

Elements of answer provided here https://github.com/plamere/spotipy/issues/828#issuecomment-1156641256

<!-- gh-comment-id:1159441053 --> @stephanebruckert commented on GitHub (Jun 18, 2022): Elements of answer provided here https://github.com/plamere/spotipy/issues/828#issuecomment-1156641256
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#408
No description provided.