[GH-ISSUE #493] Error getting token info - JSONDecodeError: Expecting value: line 1 column 1 (char 0) #293

Closed
opened 2026-02-27 23:21:50 +03:00 by kerem · 12 comments
Owner

Originally created by @tahsinac on GitHub (May 17, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/493

Hi, I've been using this library for a month daily on a simple script with no issues up until just now. I get this error now

C:\projects\nplyrbot>"C:\ProgramData\Anaconda3\python.exe" "C:\projects\nplyrbot\nplyrbotpy.py"
Traceback (most recent call last):
  File "C:\projects\nplyrbot\nplyrbotpy.py", line 99, in <module>
    lyrics_current, current = nplyrbot()
  File "C:\projects\nplyrbot\nplyrbotpy.py", line 8, in nplyrbot
    token = util.prompt_for_user_token(username, scope, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
  File "C:\ProgramData\Anaconda3\lib\site-packages\spotipy\util.py", line 88, in prompt_for_user_token
    token_info = sp_oauth.get_cached_token()
  File "C:\ProgramData\Anaconda3\lib\site-packages\spotipy\oauth2.py", line 253, in get_cached_token
    token_info = json.loads(token_info_string)
  File "C:\ProgramData\Anaconda3\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Not sure what's causing this all of a sudden, there's been no change in the script.

Originally created by @tahsinac on GitHub (May 17, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/493 Hi, I've been using this library for a month daily on a simple script with no issues up until just now. I get this error now ``` C:\projects\nplyrbot>"C:\ProgramData\Anaconda3\python.exe" "C:\projects\nplyrbot\nplyrbotpy.py" Traceback (most recent call last): File "C:\projects\nplyrbot\nplyrbotpy.py", line 99, in <module> lyrics_current, current = nplyrbot() File "C:\projects\nplyrbot\nplyrbotpy.py", line 8, in nplyrbot token = util.prompt_for_user_token(username, scope, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri) File "C:\ProgramData\Anaconda3\lib\site-packages\spotipy\util.py", line 88, in prompt_for_user_token token_info = sp_oauth.get_cached_token() File "C:\ProgramData\Anaconda3\lib\site-packages\spotipy\oauth2.py", line 253, in get_cached_token token_info = json.loads(token_info_string) File "C:\ProgramData\Anaconda3\lib\json\__init__.py", line 354, in loads return _default_decoder.decode(s) File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 357, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) ``` Not sure what's causing this all of a sudden, there's been no change in the script.
kerem 2026-02-27 23:21:50 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@tahsinac commented on GitHub (May 17, 2020):

Also, i have the latest version of the package installed.

<!-- gh-comment-id:629800391 --> @tahsinac commented on GitHub (May 17, 2020): Also, i have the latest version of the package installed.
Author
Owner

@stephanebruckert commented on GitHub (May 17, 2020):

@tahsinac I see you are using Windows. Can you please check if this https://github.com/plamere/spotipy/issues/470#issuecomment-612671070 helps

<!-- gh-comment-id:629844630 --> @stephanebruckert commented on GitHub (May 17, 2020): @tahsinac I see you are using Windows. Can you please check if this https://github.com/plamere/spotipy/issues/470#issuecomment-612671070 helps
Author
Owner

@tahsinac commented on GitHub (May 18, 2020):

Hi there, just tried it and I get a browser pop up sawing 'INVALID_CLIENT: Invalid redirect URI'. Strange as it was working just fine all this time and nothing has really changed. I went back to the Spotify web API dashboard and double checked my redirect URI. http://localhost:8888/callback/ is whitelisted.

<!-- gh-comment-id:629917278 --> @tahsinac commented on GitHub (May 18, 2020): Hi there, just tried it and I get a browser pop up sawing '_INVALID_CLIENT: Invalid redirect URI_'. Strange as it was working just fine all this time and nothing has really changed. I went back to the Spotify web API dashboard and double checked my redirect URI. _http://localhost:8888/callback/_ is whitelisted.
Author
Owner

@tahsinac commented on GitHub (May 18, 2020):

Follow-up:
Just retried running cmd.exe as admin after a quick restart and it seems to be working now.

Can you tell me why this issue came up all of a sudden and why running as admin fixed it?

<!-- gh-comment-id:629921105 --> @tahsinac commented on GitHub (May 18, 2020): Follow-up: Just retried running cmd.exe as admin after a quick restart and it seems to be working now. Can you tell me why this issue came up all of a sudden and why running as admin fixed it?
Author
Owner

@stephanebruckert commented on GitHub (May 19, 2020):

@tahsinac I'm really not sure what is happening, has something changed on spotipy or on windows?

Any chance you can try to downgrade spotipy and find which version succeeds? You can use:

pip3 install 'spotipy~=2.11.0'
pip3 install 'spotipy~=2.10.0'
pip3 install 'spotipy~=2.9.0'
... 
// stop at 2.5.0

That would be really helpful, thanks in advance

<!-- gh-comment-id:631103985 --> @stephanebruckert commented on GitHub (May 19, 2020): @tahsinac I'm really not sure what is happening, has something changed on spotipy or on windows? Any chance you can try to downgrade spotipy and find which version succeeds? You can use: pip3 install 'spotipy~=2.11.0' pip3 install 'spotipy~=2.10.0' pip3 install 'spotipy~=2.9.0' ... // stop at 2.5.0 That would be really helpful, thanks in advance
Author
Owner

@tahsinac commented on GitHub (May 20, 2020):

Using the older versions prompt a INVALID_CLIENT: Invalid redirect URI pop up, although the redirect URI I'm using is whitelisted and has been in use for a while now with no issues.

<!-- gh-comment-id:631316913 --> @tahsinac commented on GitHub (May 20, 2020): Using the older versions prompt a **INVALID_CLIENT: Invalid redirect URI** pop up, although the redirect URI I'm using is whitelisted and has been in use for a while now with no issues.
Author
Owner

@wired4life4 commented on GitHub (Jan 26, 2021):

Any fix for this ever found? I'm getting the same error. I did run my file in administrator cmd.exe and it worked and asked me to log in. In any IDE, however, it never asks to log in and gives this error.

Also looking at #567, it seems like I am required to have .cache-<username> file. A file '.cache' does not work. I am using the latest Spotipy 2.16.1

<!-- gh-comment-id:767680548 --> @wired4life4 commented on GitHub (Jan 26, 2021): Any fix for this ever found? I'm getting the same error. I did run my file in administrator cmd.exe and it worked and asked me to log in. In any IDE, however, it never asks to log in and gives this error. Also looking at #567, it seems like I am required to have .cache-\<username\> file. A file '.cache' does not work. I am using the latest Spotipy 2.16.1
Author
Owner

@stephanebruckert commented on GitHub (Jan 26, 2021):

@wired4life4 what's the content of your .cache file? (please make sure you falsify any token)

If you can't see it, it's probably hidden.

If the file is empty, you should delete it before re-running your code.

<!-- gh-comment-id:767709174 --> @stephanebruckert commented on GitHub (Jan 26, 2021): @wired4life4 what's the content of your `.cache` file? (please make sure you falsify any token) If you can't see it, it's probably [hidden](https://support.microsoft.com/en-us/windows/view-hidden-files-and-folders-in-windows-10-97fbc472-c603-9d90-91d0-1166d1d9f4b5#:~:text=Open%20File%20Explorer%20from%20the,folders%2C%20and%20drives%20and%20OK.). If the file is empty, you should delete it before re-running your code.
Author
Owner

@wired4life4 commented on GitHub (Jan 26, 2021):

@stephanebruckert Ah I just noticed I forgot to escape < > the angle brackets. The .cache-<username> file is empty and was manually created. The same for the manually created .cache file. Here is my sample script. My tokens are all stored locally in an .env file.

import os
from os.path import join, dirname
from dotenv import load_dotenv
import spotipy
from spotipy.oauth2 import SpotifyOAuth, SpotifyClientCredentials

dotenv_path = join(dirname(__file__), 'keys.env')
load_dotenv(dotenv_path)

client_username = os.environ.get('SPOTIPY_CLIENT_USERNAME')
client_id = os.environ.get('SPOTIPY_CLIENT_ID')
client_secret = os.environ.get('SPOTIPY_CLIENT_SECRET')
client_uri = os.environ.get('SPOTIPY_REDIRECT_URI')

scope = 'user-library-read'

sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=client_id,
                                               client_secret=client_secret,
                                               scope=scope,
                                               redirect_uri=client_uri))
print(sp.current_user())

Where my redirect URI is set in both the keys.env and developer dashboard as

SPOTIPY_REDIRECT_URI='https://www.github.com/wired4life4'

The .cache* file is not created upon running this script multiple times. Thanks for the reply :)

<!-- gh-comment-id:767737281 --> @wired4life4 commented on GitHub (Jan 26, 2021): @stephanebruckert Ah I just noticed I forgot to escape \< \> the angle brackets. The ```.cache-<username>``` file is empty and was manually created. The same for the manually created ```.cache``` file. Here is my sample script. My tokens are all stored locally in an .env file. ``` import os from os.path import join, dirname from dotenv import load_dotenv import spotipy from spotipy.oauth2 import SpotifyOAuth, SpotifyClientCredentials dotenv_path = join(dirname(__file__), 'keys.env') load_dotenv(dotenv_path) client_username = os.environ.get('SPOTIPY_CLIENT_USERNAME') client_id = os.environ.get('SPOTIPY_CLIENT_ID') client_secret = os.environ.get('SPOTIPY_CLIENT_SECRET') client_uri = os.environ.get('SPOTIPY_REDIRECT_URI') scope = 'user-library-read' sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=client_id, client_secret=client_secret, scope=scope, redirect_uri=client_uri)) print(sp.current_user()) ``` Where my redirect URI is set in both the keys.env and developer dashboard as ``` SPOTIPY_REDIRECT_URI='https://www.github.com/wired4life4' ``` The .cache* file is not created upon running this script multiple times. Thanks for the reply :)
Author
Owner

@stephanebruckert commented on GitHub (Jan 26, 2021):

You shouldn't have any empty files, please delete all of them.


This is not a valid redirect URI:

SPOTIPY_REDIRECT_URI='https://www.github.com/wired4life4'

Try with http://localhost:8080 instead

Also, double check or try both, but you might not need the single quotes when defining environment variables on Windows. So do:

SPOTIPY_REDIRECT_URI=http://localhost:8080

Don't forget to update your Spotify app settings.

Now when you run your code, does it work and if not, what's displayed?

<!-- gh-comment-id:767763128 --> @stephanebruckert commented on GitHub (Jan 26, 2021): You shouldn't have any empty files, please delete all of them. -------- This is not a valid redirect URI: SPOTIPY_REDIRECT_URI='https://www.github.com/wired4life4' Try with http://localhost:8080 instead Also, double check or try both, but you might not need the single quotes when defining environment variables on Windows. So do: SPOTIPY_REDIRECT_URI=http://localhost:8080 Don't forget to update your Spotify app settings. Now when you run your code, does it work and if not, what's displayed?
Author
Owner

@wired4life4 commented on GitHub (Jan 26, 2021):

It works!! Ah I see. In the docs it seemed like as long as the URI matched between the app settings and the code, it should be okay, but it looks like this is not the case. I removed all .cache* files and ran it with

SPOTIPY_REDIRECT_URI='http://localhost:80'

in my keys.env file. Upon first running, the output is

Couldn't read cache at: .cache-username
{'display_name': 'Name', 'external_urls': {'spotify': 'https://open.spotify.com/user/username'}, ... }

however, the .cache-username file is created and populated with some key-value tokens. Subsequent runs give the output above without the warning message. Thank you!! You're help is very much appreciated :)

<!-- gh-comment-id:767774868 --> @wired4life4 commented on GitHub (Jan 26, 2021): It works!! Ah I see. In the [docs](https://spotipy.readthedocs.io/en/2.16.1/#redirect-uri) it seemed like as long as the URI matched between the app settings and the code, it should be okay, but it looks like this is not the case. I removed all ```.cache*``` files and ran it with ``` SPOTIPY_REDIRECT_URI='http://localhost:80' ``` in my keys.env file. Upon first running, the output is ``` Couldn't read cache at: .cache-username {'display_name': 'Name', 'external_urls': {'spotify': 'https://open.spotify.com/user/username'}, ... } ``` however, the ```.cache-username``` file is created and populated with some key-value tokens. Subsequent runs give the output above without the warning message. Thank you!! You're help is very much appreciated :)
Author
Owner

@stephanebruckert commented on GitHub (Jan 27, 2021):

Cool!

I'm going to close this since empty files should never be created. If anyone's up for catching that exception and show a warning, feel free to open a PR

<!-- gh-comment-id:768445468 --> @stephanebruckert commented on GitHub (Jan 27, 2021): Cool! I'm going to close this since empty files should never be created. If anyone's up for catching that exception and show a warning, feel free to open a PR
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#293
No description provided.