[GH-ISSUE #706] Exception on production enviroment #418

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

Originally created by @alejandroGM0 on GitHub (Jul 13, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/706

Describe the bug
Python raise an error when using the package on production enviroment.

Your code

sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id="example",
                                                            client_secret="example"))

Here is when it raise the error
top_tracks = sp.playlist_tracks("someplaylist", limit=4)

Expected behavior
Get songs information from playlists.

Output

web           | Traceback (most recent call last):
web           |   File "/code/api/views.py", line 461, in get
web           |     top_tracks = sp.playlist_tracks("someplaylist", limit=4)
web           |   File "/usr/local/lib/python3.8/site-packages/spotipy/client.py", line 643, in playlist_tracks
web           |     return self.playlist_items(playlist_id, fields, limit, offset,
web           |   File "/usr/local/lib/python3.8/site-packages/spotipy/client.py", line 667, in playlist_items
web           |     return self._get(
web           |   File "/usr/local/lib/python3.8/site-packages/spotipy/client.py", line 291, in _get
web           |     return self._internal_call("GET", url, payload, kwargs)
web           |   File "/usr/local/lib/python3.8/site-packages/spotipy/client.py", line 221, in _internal_call
web           |     headers = self._auth_headers()
web           |   File "/usr/local/lib/python3.8/site-packages/spotipy/client.py", line 212, in _auth_headers
web           |     token = self.auth_manager.get_access_token(as_dict=False)
web           |   File "/usr/local/lib/python3.8/site-packages/spotipy/oauth2.py", line 212, in get_access_token
web           |     token_info = self.cache_handler.get_cached_token()
web           |   File "/usr/local/lib/python3.8/site-packages/spotipy/cache_handler.py", line 67, in get_cached_token
web           |     token_info = json.loads(token_info_string)
web           |   File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads
web           |     return _default_decoder.decode(s)
web           |   File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
web           |     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
web           |   File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode
web           |     raise JSONDecodeError("Expecting value", s, err.value) from None
web           | json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Environment:

  • Python 3.8.5
  • Docker, docker-compose
  • ngnix
  • Django
  • Alpine
  • Aws cloud

Additional context
When I use same code on localhost it works, perfectly.
Notes:

  • I use https on the vps
  • I'm able to make request to other apis inside the vps
Originally created by @alejandroGM0 on GitHub (Jul 13, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/706 **Describe the bug** Python raise an error when using the package on production enviroment. **Your code** ```python3 sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id="example", client_secret="example")) ``` Here is when it raise the error `top_tracks = sp.playlist_tracks("someplaylist", limit=4)` **Expected behavior** Get songs information from playlists. **Output** ``` web | Traceback (most recent call last): web | File "/code/api/views.py", line 461, in get web | top_tracks = sp.playlist_tracks("someplaylist", limit=4) web | File "/usr/local/lib/python3.8/site-packages/spotipy/client.py", line 643, in playlist_tracks web | return self.playlist_items(playlist_id, fields, limit, offset, web | File "/usr/local/lib/python3.8/site-packages/spotipy/client.py", line 667, in playlist_items web | return self._get( web | File "/usr/local/lib/python3.8/site-packages/spotipy/client.py", line 291, in _get web | return self._internal_call("GET", url, payload, kwargs) web | File "/usr/local/lib/python3.8/site-packages/spotipy/client.py", line 221, in _internal_call web | headers = self._auth_headers() web | File "/usr/local/lib/python3.8/site-packages/spotipy/client.py", line 212, in _auth_headers web | token = self.auth_manager.get_access_token(as_dict=False) web | File "/usr/local/lib/python3.8/site-packages/spotipy/oauth2.py", line 212, in get_access_token web | token_info = self.cache_handler.get_cached_token() web | File "/usr/local/lib/python3.8/site-packages/spotipy/cache_handler.py", line 67, in get_cached_token web | token_info = json.loads(token_info_string) web | File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads web | return _default_decoder.decode(s) web | File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode web | obj, end = self.raw_decode(s, idx=_w(s, 0).end()) web | File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode web | raise JSONDecodeError("Expecting value", s, err.value) from None web | json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) ``` **Environment:** - Python 3.8.5 - Docker, docker-compose - ngnix - Django - Alpine - Aws cloud **Additional context** When I use same code on localhost it works, perfectly. Notes: - I use https on the vps - I'm able to make request to other apis inside the vps
kerem 2026-02-27 23:22:31 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@alejandroGM0 commented on GitHub (Jul 13, 2021):

I tried with version 2.16.0 on my production enviroment and is working.

<!-- gh-comment-id:879221599 --> @alejandroGM0 commented on GitHub (Jul 13, 2021): I tried with version 2.16.0 on my production enviroment and is working.
Author
Owner

@Findus23 commented on GitHub (Jul 26, 2021):

see also https://github.com/plamere/spotipy/issues/493

At least for me the issue was that the server ran out of disk space and therefore the created ./.cache was empty and therefore invalid JSON on the next run.

<!-- gh-comment-id:886784024 --> @Findus23 commented on GitHub (Jul 26, 2021): see also https://github.com/plamere/spotipy/issues/493 At least for me the issue was that the server ran out of disk space and therefore the created `./.cache` was empty and therefore invalid JSON on the next run.
Author
Owner

@Peter-Schorn commented on GitHub (Jul 26, 2021):

This is definitely not a bug with spotipy. The error (on the very last line) indicates that the file which should contain the token info as JSON is empty. Delete that file and go through the authorization process again. You should never have an empty cache file.

<!-- gh-comment-id:886875196 --> @Peter-Schorn commented on GitHub (Jul 26, 2021): This is definitely not a bug with spotipy. The error (on the very last line) indicates that the file which should contain the token info as JSON is empty. Delete that file and go through the authorization process again. You should **never** have an empty cache file.
Author
Owner

@dieser-niko commented on GitHub (May 1, 2024):

@codertysmi is your issue solved or do you still need help?

<!-- gh-comment-id:2089084612 --> @dieser-niko commented on GitHub (May 1, 2024): @codertysmi is your issue solved or do you still need help?
Author
Owner

@dieser-niko commented on GitHub (May 23, 2024):

Closing as there is no activity or reply from the author.

<!-- gh-comment-id:2126618599 --> @dieser-niko commented on GitHub (May 23, 2024): Closing as there is no activity or reply from the author.
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#418
No description provided.