[GH-ISSUE #549] I get error spotipy.oauth2.SpotifyOauthError: You must either set a cache_path or a username. #330

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

Originally created by @vikivanov on GitHub (Jul 26, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/549

Describe the bug
When I try to run my script I get the following error: spotipy.oauth2.SpotifyOauthError: You must either set a cache_path or a username.

Your code
scope = 'playlist-modify-public'
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
sp.user_playlist_create(username_id, 'YouTube Converter PL', public=True, description='Test')

Expected behavior
I want to create a playlist. I tried calling other methods with sp but get the same error for all.

Output
File "D:/MyProjects/YTtoSpotify/convert.py", line 58, in create_spotify_playlist
sp.user_playlist_create(username_id, 'YouTube Converter PL', public=True, description='Test')
File "C:\Users\Acer\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py", line 628, in user_playlist_create
return self._post("users/%s/playlists" % (user,), payload=data)
File "C:\Users\Acer\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py", line 215, in _post
return self._internal_call("POST", url, payload, kwargs)
File "C:\Users\Acer\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py", line 154, in _internal_call
headers = self._auth_headers()
File "C:\Users\Acer\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py", line 145, in _auth_headers
token = self.auth_manager.get_access_token(as_dict=False)
File "C:\Users\Acer\AppData\Roaming\Python\Python38\site-packages\spotipy\oauth2.py", line 448, in get_access_token
token_info = self.get_cached_token()
File "C:\Users\Acer\AppData\Roaming\Python\Python38\site-packages\spotipy\oauth2.py", line 275, in get_cached_token
raise SpotifyOauthError(
spotipy.oauth2.SpotifyOauthError: You must either set a cache_path or a username.

Environment:

  • OS: Windows 10
  • Python version 3.8
  • spotipy version 2.13
  • your IDE (if using any) PyCharm
  • Have all the variables needed set up as env variables.
Originally created by @vikivanov on GitHub (Jul 26, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/549 **Describe the bug** When I try to run my script I get the following error: spotipy.oauth2.SpotifyOauthError: You must either set a cache_path or a username. **Your code** scope = 'playlist-modify-public' sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope)) sp.user_playlist_create(username_id, 'YouTube Converter PL', public=True, description='Test') **Expected behavior** I want to create a playlist. I tried calling other methods with sp but get the same error for all. **Output** File "D:/MyProjects/YTtoSpotify/convert.py", line 58, in create_spotify_playlist sp.user_playlist_create(username_id, 'YouTube Converter PL', public=True, description='Test') File "C:\Users\Acer\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py", line 628, in user_playlist_create return self._post("users/%s/playlists" % (user,), payload=data) File "C:\Users\Acer\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py", line 215, in _post return self._internal_call("POST", url, payload, kwargs) File "C:\Users\Acer\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py", line 154, in _internal_call headers = self._auth_headers() File "C:\Users\Acer\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py", line 145, in _auth_headers token = self.auth_manager.get_access_token(as_dict=False) File "C:\Users\Acer\AppData\Roaming\Python\Python38\site-packages\spotipy\oauth2.py", line 448, in get_access_token token_info = self.get_cached_token() File "C:\Users\Acer\AppData\Roaming\Python\Python38\site-packages\spotipy\oauth2.py", line 275, in get_cached_token raise SpotifyOauthError( spotipy.oauth2.SpotifyOauthError: You must either set a cache_path or a username. **Environment:** - OS: Windows 10 - Python version 3.8 - spotipy version 2.13 - your IDE (if using any) PyCharm - Have all the variables needed set up as env variables.
kerem 2026-02-27 23:22:02 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@vikivanov commented on GitHub (Jul 27, 2020):

Managed to go around this by passing in cache_path and redirect_uri:

    scope = 'playlist-modify-public'
    OAuth = SpotifyOAuth(scope=scope,
        redirect_uri='http://localhost:8888/callback',
        cache_path='D:/MyProjects/YTtoSpotify')
    sp = spotipy.Spotify(auth_manager=OAuth)
    sp.user_playlist_create(username_id, 'YouTube Converter PL', public=True, 
        description='Youtube Playlist converted using https://github.com/mider111/YTtoSpotify')

Now the code works and creates a playlist in my profile.

<!-- gh-comment-id:664677998 --> @vikivanov commented on GitHub (Jul 27, 2020): Managed to go around this by passing in cache_path and redirect_uri: ``` scope = 'playlist-modify-public' OAuth = SpotifyOAuth(scope=scope, redirect_uri='http://localhost:8888/callback', cache_path='D:/MyProjects/YTtoSpotify') sp = spotipy.Spotify(auth_manager=OAuth) sp.user_playlist_create(username_id, 'YouTube Converter PL', public=True, description='Youtube Playlist converted using https://github.com/mider111/YTtoSpotify') ``` Now the code works and creates a playlist in my profile.
Author
Owner

@stephanebruckert commented on GitHub (Aug 30, 2020):

Fixed in https://github.com/plamere/spotipy/pull/567

<!-- gh-comment-id:683481726 --> @stephanebruckert commented on GitHub (Aug 30, 2020): Fixed in https://github.com/plamere/spotipy/pull/567
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#330
No description provided.