Skip to content

KeyError: 'AccessToken' and Error Code 400 Unauthorized Request "Usage of this endpoint is not permitted under the Spotify Developer Terms and Developer Policy, and applicable law" #63

@kylefmohr

Description

@kylefmohr

Hi, I was able to use this yesterday, but it seems Spotify has updated something on their end. The error message looks like this:

Traceback (most recent call last):
  File "<the current directory>.venv/bin/votify", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "<the current directory>.venv/lib/python3.12/site-packages/click/core.py", line 1442, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<the current directory>.venv/lib/python3.12/site-packages/click/core.py", line 1363, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "<the current directory>.venv/lib/python3.12/site-packages/click/core.py", line 1226, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<the current directory>.venv/lib/python3.12/site-packages/click/core.py", line 794, in invoke
    return callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<the current directory>.venv/lib/python3.12/site-packages/votify/cli.py", line 404, in main
    spotify_api = SpotifyApi.from_cookies_file(cookies_path)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<the current directory>.venv/lib/python3.12/site-packages/votify/spotify_api.py", line 66, in from_cookies_file
    return cls(sp_dc=sp_dc)
           ^^^^^^^^^^^^^^^^
  File "<the current directory>.venv/lib/python3.12/site-packages/votify/spotify_api.py", line 46, in __init__
    self._set_session()
  File "<the current directory>.venv/lib/python3.12/site-packages/votify/spotify_api.py", line 96, in _set_session
    self._set_session_info()
  File "<the current directory>.venv/lib/python3.12/site-packages/votify/spotify_api.py", line 120, in _set_session_info
    "authorization": f"Bearer {self.session_info['accessToken']}",
                               ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'accessToken'

I added the following line to spotify_api.py@L117:

        self.session_info = session_info_response.json()
+        print("Session info:", self.session_info)
        self.session.headers.update(

and discovered this error:

[INFO     18:17:21] Starting Votify
Session info: {'totpVerExpired': 'error', 'totpValidUntil': '2025-08-05T09:00:00.000Z', 'error': {'code': 400, 'message': 'Unauthorized request', 'extra': {'_notes': 'Usage of this endpoint is not permitted under the Spotify Developer Terms and Developer Policy, and applicable law'}}}
Traceback (most recent call last):
<Rest of the original error>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions