[GH-ISSUE #785] json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) when using playlist_items() #486

Closed
opened 2026-02-27 23:22:53 +03:00 by kerem · 3 comments
Owner

Originally created by @IchbinLuka on GitHub (Feb 23, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/785

Bug
When calling playlist_items() I get a JSONDecodeError. Below is one the examples which raises this error. I've checked multiple times that both the client-secret and client-id are correct. The weird thing is that this worked perfectly until a few weeks ago.

Code

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
from src.access_tokens import SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET

sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials(client_id=SPOTIFY_CLIENT_ID,
                                                                         client_secret=SPOTIFY_CLIENT_SECRET))

pl_id = 'spotify:playlist:5RIbzhG2QqdkaP24iXLnZX'
offset = 0

while True:
    response = sp.playlist_items(pl_id,
                                 offset=offset,
                                 fields='items.track.id,total',
                                 additional_types=['track'])

    if len(response['items']) == 0:
        break

    print(response['items'])
    offset = offset + len(response['items'])
    print(offset, "/", response['total'])

Output

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\xxxx\AppData\Local\JetBrains\Toolbox\apps\PyCharm-C\ch-0\212.5080.64\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Users\xxxx\AppData\Local\JetBrains\Toolbox\apps\PyCharm-C\ch-0\212.5080.64\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/xxxx/PycharmProjects/MusikBot/test.py", line 12, in <module>
    response = sp.playlist_items(pl_id,
  File "C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\spotipy\client.py", line 673, in playlist_items
    return self._get(
  File "C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\spotipy\client.py", line 297, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\spotipy\client.py", line 221, in _internal_call
    headers = self._auth_headers()
  File "C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\spotipy\client.py", line 212, in _auth_headers
    token = self.auth_manager.get_access_token(as_dict=False)
  File "C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\spotipy\oauth2.py", line 234, in get_access_token
    token_info = self.cache_handler.get_cached_token()
  File "C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\spotipy\cache_handler.py", line 70, in get_cached_token
    token_info = json.loads(token_info_string)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Environment:

  • OS: Windows 10
  • Python version 3.9.10
  • spotipy version 2.19.0
  • IDE: PyCharm Community
Originally created by @IchbinLuka on GitHub (Feb 23, 2022). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/785 **Bug** When calling playlist_items() I get a JSONDecodeError. Below is one the [examples](https://github.com/plamere/spotipy/tree/master/examples) which raises this error. I've checked multiple times that both the client-secret and client-id are correct. The weird thing is that this worked perfectly until a few weeks ago. **Code** ``` import spotipy from spotipy.oauth2 import SpotifyClientCredentials from src.access_tokens import SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials(client_id=SPOTIFY_CLIENT_ID, client_secret=SPOTIFY_CLIENT_SECRET)) pl_id = 'spotify:playlist:5RIbzhG2QqdkaP24iXLnZX' offset = 0 while True: response = sp.playlist_items(pl_id, offset=offset, fields='items.track.id,total', additional_types=['track']) if len(response['items']) == 0: break print(response['items']) offset = offset + len(response['items']) print(offset, "/", response['total']) ``` **Output** ``` Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Users\xxxx\AppData\Local\JetBrains\Toolbox\apps\PyCharm-C\ch-0\212.5080.64\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "C:\Users\xxxx\AppData\Local\JetBrains\Toolbox\apps\PyCharm-C\ch-0\212.5080.64\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/xxxx/PycharmProjects/MusikBot/test.py", line 12, in <module> response = sp.playlist_items(pl_id, File "C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\spotipy\client.py", line 673, in playlist_items return self._get( File "C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\spotipy\client.py", line 297, in _get return self._internal_call("GET", url, payload, kwargs) File "C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\spotipy\client.py", line 221, in _internal_call headers = self._auth_headers() File "C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\spotipy\client.py", line 212, in _auth_headers token = self.auth_manager.get_access_token(as_dict=False) File "C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\spotipy\oauth2.py", line 234, in get_access_token token_info = self.cache_handler.get_cached_token() File "C:\Users\xxxx\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\spotipy\cache_handler.py", line 70, in get_cached_token token_info = json.loads(token_info_string) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\json\__init__.py", line 346, in loads return _default_decoder.decode(s) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2800.0_x64__qbz5n2kfra8p0\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) ``` **Environment:** - OS: Windows 10 - Python version 3.9.10 - spotipy version 2.19.0 - IDE: PyCharm Community
kerem 2026-02-27 23:22:53 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@Peter-Schorn commented on GitHub (Feb 24, 2022):

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

This indicates that the data was completely empty, which is not valid JSON.

I tested your code and could not reproduce this error. I received all pages of the playlist. Do you experience this error consistently?

<!-- gh-comment-id:1049349337 --> @Peter-Schorn commented on GitHub (Feb 24, 2022): > json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) This indicates that the data was completely empty, which is not valid JSON. I tested your code and could not reproduce this error. I received all pages of the playlist. Do you experience this error consistently?
Author
Owner

@IchbinLuka commented on GitHub (Feb 25, 2022):

Deleting the .cache file solved the problem. The access token saved there probably expired and spotipy didn't generate a new one

<!-- gh-comment-id:1050976525 --> @IchbinLuka commented on GitHub (Feb 25, 2022): Deleting the .cache file solved the problem. The access token saved there probably expired and spotipy didn't generate a new one
Author
Owner

@Peter-Schorn commented on GitHub (Feb 25, 2022):

The access token saved there probably expired and spotipy didn't generate a new one

No that can't be the cause of this error. If you make a request with an expired/invalid access token, you get a very specific type of error.

<!-- gh-comment-id:1051046594 --> @Peter-Schorn commented on GitHub (Feb 25, 2022): > The access token saved there probably expired and spotipy didn't generate a new one No that can't be the cause of this error. If you make a request with an expired/invalid access token, you get a very specific type of error.
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#486
No description provided.