import spotipy
import requests
import sys
import spotipy.util as util
from spotipy.oauth2 import SpotifyClientCredentials
# Setup the credentials
client_credentials_manager =
SpotifyClientCredentials(client_id=client_id,client_secret=client_secret)
# Make the connection
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager,auth=access_token)
sp.current_user()
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
~\Anaconda\lib\site-packages\spotipy\client.py in _internal_call(self,
method, url, payload, params)
118 try:
--> 119 r.raise_for_status()
120 except:
~\Anaconda\lib\site-packages\requests\models.py in raise_for_status(self)
934 if http_error_msg:
--> 935 raise HTTPError(http_error_msg, response=self)
936
HTTPError: 401 Client Error: Unauthorized for url:
https://api.spotify.com/v1/me/
During handling of the above exception, another exception occurred:
SpotifyException Traceback (most recent call last)
<ipython-input-12-a36bf58a0704> in <module>()
----> 1 sp.current_user()
~\Anaconda\lib\site-packages\spotipy\client.py in current_user(self)
572 An alias for the 'me' method.
573 '''
--> 574 return self.me()
575
576 def current_user_saved_albums(self, limit=20, offset=0):
~\Anaconda\lib\site-packages\spotipy\client.py in me(self)
566 An alias for the 'current_user' method.
567 '''
--> 568 return self._get('me/')
569
570 def current_user(self):
~\Anaconda\lib\site-packages\spotipy\client.py in _get(self, url, args,
payload, **kwargs)
144 while retries > 0:
145 try:
--> 146 return self._internal_call('GET', url, payload,
kwargs)
147 except SpotifyException as e:
148 retries -= 1
~\Anaconda\lib\site-packages\spotipy\client.py in _internal_call(self,
method, url, payload, params)
122 raise SpotifyException(r.status_code,
123 -1, '%s:\n %s' % (r.url, r.json()['error']
['message']),
--> 124 headers=r.headers)
125 else:
126 raise SpotifyException(r.status_code,
SpotifyException: http status: 401, code:-1 -
https://api.spotify.com/v1/me/:
Unauthorized.
这是连接到 spotify api 的正确方法吗?我一直在尝试通过需要身份验证令牌的 spotify API 获取详细信息。我的代码中确实包含所有 3 个(只是未在此处发布)。我仍然收到这个错误的请求错误。