spotDL / spotify-downloader

Download your Spotify playlists and songs along with album art and metadata (from YouTube if a match is found).
https://spotdl.readthedocs.io/en/latest/
MIT License
15.55k stars 1.48k forks source link

Refresh access token error #2115

Closed llessi06 closed 3 weeks ago

llessi06 commented 3 weeks ago

System OS

Linux

Python Version

3.10 (CPython)

Install Source

pip / PyPi

Install version / commit hash

v4.2.5

Expected Behavior vs Actual Behavior

Actual Behavior: I create an Spotify App to Call their API copied the Client ID and the Secret to the Config File and when I try to download something I get this error

Expected Behavioru: spotdl should get a new Token or something like this from Spotify and download my songs

Steps to reproduce - Ensure to include actual links!

  1. Create an new Spotify app at their developer dashboard
  2. Copy the ID and the Secret to the config file
  3. Download something

Traceback

An error occurred
╭───────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────╮
│ /usr/local/lib/python3.10/dist-packages/spotipy/oauth2.py:588 in refresh_access_token                                │
│                                                                                                                      │
│    585 │   │   │   │   proxies=self.proxies,                                                                         │
│    586 │   │   │   │   timeout=self.requests_timeout,                                                                │
│    587 │   │   │   )                                                                                                 │
│ ❱  588 │   │   │   response.raise_for_status()                                                                       │
│    589 │   │   │   token_info = response.json()                                                                      │
│    590 │   │   │   token_info = self._add_custom_values_to_token_info(token_info)                                    │
│    591 │   │   │   if "refresh_token" not in token_info:                                                             │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/requests/models.py:1021 in raise_for_status                                  │
│                                                                                                                      │
│   1018 │   │   │   )                                                                                                 │
│   1019 │   │                                                                                                         │
│   1020 │   │   if http_error_msg:                                                                                    │
│ ❱ 1021 │   │   │   raise HTTPError(http_error_msg, response=self)                                                    │
│   1022 │                                                                                                             │
│   1023 │   def close(self):                                                                                          │
│   1024 │   │   """Releases the connection back to the pool. Once this method has been                                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
HTTPError: 400 Client Error: Bad Request for url: https://accounts.spotify.com/api/token

During handling of the above exception, another exception occurred:

╭───────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────╮
│ /usr/local/lib/python3.10/dist-packages/spotdl/console/entry_point.py:142 in console_entry_point                     │
│                                                                                                                      │
│   139 │   try:                                                                                                       │
│   140 │   │   # Pick the operation to perform                                                                        │
│   141 │   │   # based on the name and run it!                                                                        │
│ ❱ 142 │   │   OPERATIONS[arguments.operation](                                                                       │
│   143 │   │   │   query=arguments.query,                                                                             │
│   144 │   │   │   downloader=downloader,                                                                             │
│   145 │   │   )                                                                                                      │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/spotdl/console/download.py:25 in download                                    │
│                                                                                                                      │
│   22 │   """                                                                                                         │
│   23 │                                                                                                               │
│   24 │   # Parse the query                                                                                           │
│ ❱ 25 │   songs = get_simple_songs(                                                                                   │
│   26 │   │   query,                                                                                                  │
│   27 │   │   use_ytm_data=downloader.settings["ytm_data"],                                                           │
│   28 │   │   playlist_numbering=downloader.settings["playlist_numbering"],                                           │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/spotdl/utils/search.py:289 in get_simple_songs                               │
│                                                                                                                      │
│   286 │   │   │   │   │   # Append to songs                                                                          │
│   287 │   │   │   │   │   songs.append(Song.from_dict(track))                                                        │
│   288 │   │   else:                                                                                                  │
│ ❱ 289 │   │   │   songs.append(Song.from_search_term(request))                                                       │
│   290 │                                                                                                              │
│   291 │   for song_list in lists:                                                                                    │
│   292 │   │   logger.info(                                                                                           │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/spotdl/types/song.py:171 in from_search_term                                 │
│                                                                                                                      │
│   168 │   │   - The Song object.                                                                                     │
│   169 │   │   """                                                                                                    │
│   170 │   │                                                                                                          │
│ ❱ 171 │   │   raw_search_results = Song.search(search_term)                                                          │
│   172 │   │                                                                                                          │
│   173 │   │   if len(raw_search_results["tracks"]["items"]) == 0:                                                    │
│   174 │   │   │   raise SongError(f"No results found for: {search_term}")                                            │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/spotdl/types/song.py:152 in search                                           │
│                                                                                                                      │
│   149 │   │   - The raw search results                                                                               │
│   150 │   │   """                                                                                                    │
│   151 │   │   spotify_client = SpotifyClient()                                                                       │
│ ❱ 152 │   │   raw_search_results = spotify_client.search(search_term)                                                │
│   153 │   │                                                                                                          │
│   154 │   │   if raw_search_results is None:                                                                         │
│   155 │   │   │   raise SongError(f"Spotipy error, no response: {search_term}")                                      │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/spotipy/client.py:587 in search                                              │
│                                                                                                                      │
│    584 │   │   │   │   - market - An ISO 3166-1 alpha-2 country code or the string                                   │
│    585 │   │   │   │   │   │      from_token.                                                                        │
│    586 │   │   """                                                                                                   │
│ ❱  587 │   │   return self._get(                                                                                     │
│    588 │   │   │   "search", q=q, limit=limit, offset=offset, type=type, market=market                               │
│    589 │   │   )                                                                                                     │
│    590                                                                                                               │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/spotdl/utils/spotify.py:195 in _get                                          │
│                                                                                                                      │
│   192 │   │   retries = self.max_retries  # type: ignore # pylint: disable=E1101                                     │
│   193 │   │   while response is None:                                                                                │
│   194 │   │   │   try:                                                                                               │
│ ❱ 195 │   │   │   │   response = self._internal_call("GET", url, payload, kwargs)                                    │
│   196 │   │   │   except (requests.exceptions.Timeout, requests.ConnectionError) as exc:                             │
│   197 │   │   │   │   retries -= 1                                                                                   │
│   198 │   │   │   │   if retries <= 0:                                                                               │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/spotipy/client.py:247 in _internal_call                                      │
│                                                                                                                      │
│    244 │   │   args = dict(params=params)                                                                            │
│    245 │   │   if not url.startswith("http"):                                                                        │
│    246 │   │   │   url = self.prefix + url                                                                           │
│ ❱  247 │   │   headers = self._auth_headers()                                                                        │
│    248 │   │                                                                                                         │
│    249 │   │   if "content_type" in args["params"]:                                                                  │
│    250 │   │   │   headers["Content-Type"] = args["params"]["content_type"]                                          │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/spotipy/client.py:238 in _auth_headers                                       │
│                                                                                                                      │
│    235 │   │   if not self.auth_manager:                                                                             │
│    236 │   │   │   return {}                                                                                         │
│    237 │   │   try:                                                                                                  │
│ ❱  238 │   │   │   token = self.auth_manager.get_access_token(as_dict=False)                                         │
│    239 │   │   except TypeError:                                                                                     │
│    240 │   │   │   token = self.auth_manager.get_access_token()                                                      │
│    241 │   │   return {"Authorization": "Bearer {0}".format(token)}                                                  │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/spotipy/oauth2.py:525 in get_access_token                                    │
│                                                                                                                      │
│    522 │   │   │   │   stacklevel=2,                                                                                 │
│    523 │   │   │   )                                                                                                 │
│    524 │   │   if check_cache:                                                                                       │
│ ❱  525 │   │   │   token_info = self.validate_token(self.cache_handler.get_cached_token())                           │
│    526 │   │   │   if token_info is not None:                                                                        │
│    527 │   │   │   │   if self.is_token_expired(token_info):                                                         │
│    528 │   │   │   │   │   token_info = self.refresh_access_token(                                                   │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/spotipy/oauth2.py:380 in validate_token                                      │
│                                                                                                                      │
│    377 │   │   │   return None                                                                                       │
│    378 │   │                                                                                                         │
│    379 │   │   if self.is_token_expired(token_info):                                                                 │
│ ❱  380 │   │   │   token_info = self.refresh_access_token(                                                           │
│    381 │   │   │   │   token_info["refresh_token"]                                                                   │
│    382 │   │   │   )                                                                                                 │
│    383                                                                                                               │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/spotipy/oauth2.py:596 in refresh_access_token                                │
│                                                                                                                      │
│    593 │   │   │   self.cache_handler.save_token_to_cache(token_info)                                                │
│    594 │   │   │   return token_info                                                                                 │
│    595 │   │   except requests.exceptions.HTTPError as http_error:                                                   │
│ ❱  596 │   │   │   self._handle_oauth_error(http_error)                                                              │
│    597 │                                                                                                             │
│    598 │   def _add_custom_values_to_token_info(self, token_info):                                                   │
│    599 │   │   """                                                                                                   │
│                                                                                                                      │
│ /usr/local/lib/python3.10/dist-packages/spotipy/oauth2.py:146 in _handle_oauth_error                                 │
│                                                                                                                      │
│    143 │   │   │   error = response.text or None                                                                     │
│    144 │   │   │   error_description = None                                                                          │
│    145 │   │                                                                                                         │
│ ❱  146 │   │   raise SpotifyOauthError(                                                                              │
│    147 │   │   │   'error: {0}, error_description: {1}'.format(                                                      │
│    148 │   │   │   │   error, error_description                                                                      │
│    149 │   │   │   ),                                                                                                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
SpotifyOauthError: error: invalid_client, error_description: Invalid client

Other details

No response

llessi06 commented 3 weeks ago

Must have been a problem on Spotify's part, because it now works without any changes. Problem solved

karma-riuk commented 1 week ago

You really didn't do anything to fix it? I have the same issue but it doesn't seem to go away