[GH-ISSUE #1151] An error occurred: can only concatenate tuple (not "str") to tuple when using Spotipy functions #678

Closed
opened 2026-02-28 00:00:46 +03:00 by kerem · 7 comments
Owner

Originally created by @olistori on GitHub (Jul 28, 2024).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1151

Think there is a problem with how spotipy is handling strings in some functions. Atleast .track() and .playlist_tracks()
here is a code snipped im using, query is a link to a spotify playlist.

        playlist_id = query.split("/")[-1].split("?")[0]
        print(playlist_id)
        try:
            playlist = spotify.playlist_tracks(playlist_id)
        except Exception as e:
            print(f'Error while getting playlist data: {str(e)}')
            logging.error(f'Error while getting playlist data: {str(e)}')

ive tried using URL, URI and Playlist/track id

Output
An error occurred: can only concatenate tuple (not "str") to tuple

Environment:

  • OS: Windows
  • Python version 3.12.3
  • spotipy version 2.24.0
Originally created by @olistori on GitHub (Jul 28, 2024). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1151 Think there is a problem with how spotipy is handling strings in some functions. Atleast .track() and .playlist_tracks() here is a code snipped im using, query is a link to a spotify playlist. playlist_id = query.split("/")[-1].split("?")[0] print(playlist_id) try: playlist = spotify.playlist_tracks(playlist_id) except Exception as e: print(f'Error while getting playlist data: {str(e)}') logging.error(f'Error while getting playlist data: {str(e)}') ive tried using URL, URI and Playlist/track id **Output** An error occurred: can only concatenate tuple (not "str") to tuple **Environment:** - OS: Windows - Python version 3.12.3 - spotipy version 2.24.0
kerem 2026-02-28 00:00:46 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@stephanebruckert commented on GitHub (Jul 28, 2024):

What does playlist_id print?

<!-- gh-comment-id:2254603683 --> @stephanebruckert commented on GitHub (Jul 28, 2024): What does `playlist_id` print?
Author
Owner

@olistori commented on GitHub (Jul 28, 2024):

3ntvwrQ3TSHo2k3wFjN62s i guess its the id for the playlist

on .track ive tried the url, id and ur:

        try:
            track = spotify.track(query)
        except Exception as e:
            print(f"An error occurred: {e}")
            logging.error(f"An error occurred: {e}")
<!-- gh-comment-id:2254604386 --> @olistori commented on GitHub (Jul 28, 2024): 3ntvwrQ3TSHo2k3wFjN62s i guess its the id for the playlist on .track ive tried the url, id and ur: try: track = spotify.track(query) except Exception as e: print(f"An error occurred: {e}") logging.error(f"An error occurred: {e}")
Author
Owner

@stephanebruckert commented on GitHub (Jul 28, 2024):

Okay strange, could you please share the full stack trace you are seeing?

<!-- gh-comment-id:2254605109 --> @stephanebruckert commented on GitHub (Jul 28, 2024): Okay strange, could you please share the full stack trace you are seeing?
Author
Owner

@olistori commented on GitHub (Jul 28, 2024):

When i put logging level in DEBUG, this is all i get when i try to call the functions:

DEBUG:spotipy.cache_handler:cache does not exist at: .cache
DEBUG:spotipy.cache_handler:cache does not exist at: .cache
ERROR:root:An error occurred: can only concatenate tuple (not "str") to tuple

<!-- gh-comment-id:2254606947 --> @olistori commented on GitHub (Jul 28, 2024): When i put logging level in DEBUG, this is all i get when i try to call the functions: DEBUG:spotipy.cache_handler:cache does not exist at: .cache DEBUG:spotipy.cache_handler:cache does not exist at: .cache ERROR:root:An error occurred: can only concatenate tuple (not "str") to tuple
Author
Owner

@stephanebruckert commented on GitHub (Jul 28, 2024):

The stack trace shows the exact line where there is an issue, could you share that? It's basically the full error you are seeing, please copy paste everything you see

Edit: I just saw you are swallowing the error. To see the full error in here you need to either 1) remove the whole try/except

    track = spotify.track(query)

or 2) throw the error again:

    try:
        track = spotify.track(query)
    except Exception as e:
        print(f"An error occurred: {e}")
        logging.error(f"An error occurred: {e}")
        throw(e)

or 3) print the stack trace from Except https://stackoverflow.com/a/16946886/1515819:

    import traceback

    try:
        track = spotify.track(query)
    except Exception as e:
        print(f"An error occurred: {e}")
        logging.error(f"An error occurred: {e}")
        traceback.print_exc()
<!-- gh-comment-id:2254648548 --> @stephanebruckert commented on GitHub (Jul 28, 2024): The stack trace shows the exact line where there is an issue, could you share that? It's basically the full error you are seeing, please copy paste everything you see Edit: I just saw you are swallowing the error. To see the full error in here you need to either 1) remove the whole try/except track = spotify.track(query) or 2) throw the error again: try: track = spotify.track(query) except Exception as e: print(f"An error occurred: {e}") logging.error(f"An error occurred: {e}") throw(e) or 3) print the stack trace from Except https://stackoverflow.com/a/16946886/1515819: import traceback try: track = spotify.track(query) except Exception as e: print(f"An error occurred: {e}") logging.error(f"An error occurred: {e}") traceback.print_exc()
Author
Owner

@olistori commented on GitHub (Jul 28, 2024):

Ahh i see, the error is not with the function call. Looks like its with my credentials

An error occurred: can only concatenate tuple (not "str") to tuple
Traceback (most recent call last):
File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\client.py", line 242, in _auth_headers
token = self.auth_manager.get_access_token(as_dict=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\oauth2.py", line 229, in get_access_token
token_info = self._request_access_token()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\oauth2.py", line 238, in _request_access_token
headers = _make_authorization_headers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\oauth2.py", line 53, in _make_authorization_headers
str(client_id + ":" + client_secret).encode("ascii")
~~~~~~~~~~^~~~~
TypeError: can only concatenate tuple (not "str") to tuple

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\plexy\Desktop\Discord Bot\Discord-bot-pip\Discord_bot.py", line 318, in play
track = spotify.track(query)
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\client.py", line 375, in track
return self._get("tracks/" + trid, market=market)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\client.py", line 327, in _get
return self._internal_call("GET", url, payload, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\client.py", line 251, in _internal_call
headers = self._auth_headers()
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\client.py", line 244, in _auth_headers
token = self.auth_manager.get_access_token()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\oauth2.py", line 229, in get_access_token
token_info = self._request_access_token()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\oauth2.py", line 238, in _request_access_token
headers = _make_authorization_headers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\oauth2.py", line 53, in _make_authorization_headers
str(client_id + ":" + client_secret).encode("ascii")
~~~~~~~~~~^~~~~
TypeError: can only concatenate tuple (not "str") to tuple

this is how i set the credentials:

spotify = spotipy.Spotify(
    client_credentials_manager=SpotifyClientCredentials(
        client_id=SPOTIFY_CLIENT_ID, 
        client_secret=SPOTIFY_CLIENT_SECRET
    )
)
<!-- gh-comment-id:2254674058 --> @olistori commented on GitHub (Jul 28, 2024): Ahh i see, the error is not with the function call. Looks like its with my credentials An error occurred: can only concatenate tuple (not "str") to tuple Traceback (most recent call last): File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\client.py", line 242, in _auth_headers token = self.auth_manager.get_access_token(as_dict=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\oauth2.py", line 229, in get_access_token token_info = self._request_access_token() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\oauth2.py", line 238, in _request_access_token headers = _make_authorization_headers( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\oauth2.py", line 53, in _make_authorization_headers str(client_id + ":" + client_secret).encode("ascii") ~~~~~~~~~~^~~~~ TypeError: can only concatenate tuple (not "str") to tuple During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\plexy\Desktop\Discord Bot\Discord-bot-pip\Discord_bot.py", line 318, in play track = spotify.track(query) ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\client.py", line 375, in track return self._get("tracks/" + trid, market=market) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\client.py", line 327, in _get return self._internal_call("GET", url, payload, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\client.py", line 251, in _internal_call headers = self._auth_headers() ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\client.py", line 244, in _auth_headers token = self.auth_manager.get_access_token() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\oauth2.py", line 229, in get_access_token token_info = self._request_access_token() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\oauth2.py", line 238, in _request_access_token headers = _make_authorization_headers( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\plexy\AppData\Local\Programs\Python\Python312\Lib\site-packages\spotipy\oauth2.py", line 53, in _make_authorization_headers str(client_id + ":" + client_secret).encode("ascii") ~~~~~~~~~~^~~~~ TypeError: can only concatenate tuple (not "str") to tuple this is how i set the credentials: ``` spotify = spotipy.Spotify( client_credentials_manager=SpotifyClientCredentials( client_id=SPOTIFY_CLIENT_ID, client_secret=SPOTIFY_CLIENT_SECRET ) ) ```
Author
Owner

@olistori commented on GitHub (Jul 28, 2024):

It was a problem with my credential files, its contained extra "," after each credential. it fixed the problem. Sorry to bother

<!-- gh-comment-id:2254679814 --> @olistori commented on GitHub (Jul 28, 2024): It was a problem with my credential files, its contained extra "," after each credential. it fixed the problem. Sorry to bother
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#678
No description provided.