Skip to content

Spotify: Improve 503 error handling#6871

Open
arsaboo wants to merge 9 commits into
beetbox:masterfrom
arsaboo:spotify
Open

Spotify: Improve 503 error handling#6871
arsaboo wants to merge 9 commits into
beetbox:masterfrom
arsaboo:spotify

Conversation

@arsaboo

@arsaboo arsaboo commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Spotify currently crashes out on 503 errors.

spotify: Service Unavailable.
Traceback (most recent call last):
  File "/home/arsaboo/.local/lib/python3.10/site-packages/beetsplug/spotify.py", line 244, in _handle_response
    response.raise_for_status()
  File "/home/arsaboo/.local/lib/python3.10/site-packages/requests/models.py", line 1167, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 503 Server Error: Service Unavailable for url: https://api.spotify.com/v1/tracks?ids=7ElISEDbwXtbB4xAvFRLqb%2C1DgdyYtZjfmBOxLuDLHXyH%2C0AeK8BB9Kk7qxyUgCfEwLO%2C6SJyEptZ7MiFJYe9FUbk7Q%2C5C9GZT725aQAdUT97hjaiO%2C0nGkSdNwjPh0tpqQU0FCCR%2C7EsWEd2s6hUUNw3I2QqKrn%2C3LfDSh8oDROFmebWrUq7De%2C036co96fRtoFd8n7pvklci%2C72sBOZVBWsfgKRWAF61jDA%2C3T6PwNpROC4WkWvrnqIcCJ%2C1USz6iqnhAnfHCcnjylrLa%2C7w6sxU9PQT8nJYzqGswOvM%2C4KeexCKGpjkBJS633QgxS2%2C0JuHzqHYYrauekCOUx4RrY%2C5cumiCqwlT9GAg2uktOZlg%2C2GbA6HFXqOGndhpPg42ifK%2C55nrl1ScrRDCv1ORLoEMlG%2C3YwLux5noWLxHhhE3OdIHS%2C1lCRbQsiWmNQUUSGYNvGT8

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/arsaboo/.local/bin/beet", line 6, in <module>
    sys.exit(main())
  File "/home/arsaboo/.local/lib/python3.10/site-packages/beets/ui/__init__.py", line 962, in main
    _raw_main(args)
  File "/home/arsaboo/.local/lib/python3.10/site-packages/beets/ui/__init__.py", line 903, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/home/arsaboo/.local/lib/python3.10/site-packages/beetsplug/spotify.py", line 570, in func
    self._fetch_info(lib, items, ui.should_write(), opts.force_refetch)
  File "/home/arsaboo/.local/lib/python3.10/site-packages/beetsplug/spotify.py", line 844, in _fetch_info
    track_details_by_id = self.get_track_details_by_id(unique_track_ids)
  File "/home/arsaboo/.local/lib/python3.10/site-packages/beetsplug/spotify.py", line 753, in get_track_details_by_id
    track_data = self._handle_response(
  File "/home/arsaboo/.local/lib/python3.10/site-packages/beetsplug/spotify.py", line 294, in _handle_response
    raise APIError("Service Unavailable.")
beetsplug.spotify.APIError: Service Unavailable.

This PR adds a retry mechanism that Spotify recommends for transient 503 errors.

To Do

  • Changelog. (Add an entry to docs/changelog.rst to the bottom of one of the lists near the top of the document.)

@arsaboo
arsaboo marked this pull request as ready for review July 24, 2026 14:14
@github-actions github-actions Bot added the spotify spotify plugin label Jul 24, 2026
@arsaboo
arsaboo requested a review from a team as a code owner July 24, 2026 14:14
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.62%. Comparing base (4782acb) to head (cad27b5).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
beetsplug/spotify.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6871      +/-   ##
==========================================
- Coverage   75.64%   75.62%   -0.03%     
==========================================
  Files         163      163              
  Lines       21317    21318       +1     
  Branches     3361     3361              
==========================================
- Hits        16126    16122       -4     
- Misses       4402     4405       +3     
- Partials      789      791       +2     
Files with missing lines Coverage Δ
beetsplug/spotify.py 63.29% <0.00%> (-0.17%) ⬇️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

spotify spotify plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant