Skip to content

Fix Spotify metadata provider: send token via Authorization header - #468

Open
nicobgr wants to merge 1 commit into
krateng:masterfrom
nicobgr:fix/spotify-auth-header
Open

Fix Spotify metadata provider: send token via Authorization header#468
nicobgr wants to merge 1 commit into
krateng:masterfrom
nicobgr:fix/spotify-auth-header

Conversation

@nicobgr

@nicobgr nicobgr commented Aug 30, 2026

Copy link
Copy Markdown

Fixes #467

Problem

Spotify's Web API no longer accepts access_token as a query parameter on /v1/search - it must be sent as an Authorization: Bearer <token> header instead. Requests built the old way get rejected with an error-shaped JSON response that handle_json_result_error doesn't expect (no tracks/albums/artists key), which crashes with an unhandled TypeError.

Since thirdparty/__init__.py's get_image_*_all functions log e.__doc__ (the exception class's docstring) instead of the actual error, this surfaces in the logs as the generic, undiagnosable:

[thirdparty] Error getting album image from Spotify: Inappropriate argument type.

...on every single lookup (verified: 0/163 successful Spotify lookups in a real instance's logs before this fix). It silently falls through to the next provider, so it's easy to miss - the only symptom is worse-than-expected cover art coverage.

I believe this also explains #424 ("Mapping key not found" = KeyError.__doc__, same class of problem, different exception).

Fix

  • maloja/thirdparty/spotify.py: override get_image_track/get_image_artist/get_image_album to send the token via the Authorization header instead of the URL, drop access_token={token} from the URL templates, and make handle_json_result_error defensive against non-dict / error-shaped responses instead of crashing on them.
  • maloja/thirdparty/__init__.py: log repr(e) instead of e.__doc__ in the three get_image_*_all functions, so future failures (for any provider, not just Spotify) are actually diagnosable from the logs instead of always showing the same generic exception-class docstring.

Testing

Verified against a real Maloja instance (v3.2.6) with valid Spotify credentials:

  • Before: 0 successful Spotify image lookups across ~160 real requests, all logging the generic TypeError message.
  • After: confirmed real i.scdn.co image URLs returned for artist/album/track lookups that previously failed, including via real scrobbles from a live client (not just synthetic tests), e.g. [thirdparty] Got album image for (['Sia'], '1000 Forms Of Fear') from Spotify.

Spotify's Web API no longer accepts access_token as a query parameter
on /v1/search - it must be sent as an "Authorization: Bearer" header.
Requests made the old way get rejected with an error response that
handle_json_result_error doesn't expect, crashing with an unhandled
TypeError on every single lookup.

- Override get_image_track/artist/album in the Spotify provider to
  send the token via the Authorization header instead of the URL,
  and make handle_json_result_error defensive against non-dict /
  error-shaped responses instead of crashing.
- Log the real exception (repr(e)) instead of e.__doc__ in
  thirdparty/__init__.py's get_image_*_all functions - e.__doc__ is
  just the exception class's generic docstring (e.g. "Inappropriate
  argument type." for any TypeError), which made this bug and others
  like it (krateng#424) effectively undiagnosable from the logs.

Fixes krateng#467
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant