Skip to content

Stability issues with requests to the search endpoint of the Spotify API #58

Description

@a-rich

Describe the bug
The Spotify playlist builder routinely fails when making requests to the Spotify API (see example stack trace below). Without having looked into very much at all, my initial assumption is that the artist and / or title used to form search query strings has bad characters.

  File "/Users/alrichards/.pyenv/versions/3.8.13/envs/djtools/lib/python3.8/site-packages/spotipy/client.py", line 245, in _internal_call
    response.raise_for_status()
  File "/Users/alrichards/.pyenv/versions/3.8.13/envs/djtools/lib/python3.8/site-packages/requests/models.py", line 1022, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.spotify.com/v1/search?query=Gnasha%2BMe%2B%26%2BU%2B&type=track&offset=1000&limit=50

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/alrichards/.pyenv/versions/3.8.13/envs/djtools/lib/python3.8/site-packages/djtools/spotify/spotify_playlist_builder.py", line 389, in filter_results
    results = spotify.next(results["tracks"])
  File "/Users/alrichards/.pyenv/versions/3.8.13/envs/djtools/lib/python3.8/site-packages/spotipy/client.py", line 321, in next
    return self._get(result["next"])
  File "/Users/alrichards/.pyenv/versions/3.8.13/envs/djtools/lib/python3.8/site-packages/spotipy/client.py", line 297, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/Users/alrichards/.pyenv/versions/3.8.13/envs/djtools/lib/python3.8/site-packages/spotipy/client.py", line 267, in _internal_call
    raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 400, code:-1 - https://api.spotify.com/v1/search?query=Gnasha%2BMe%2B%26%2BU%2B&type=track&offset=1000&limit=50:
 Bad request., reason: None

To Reproduce
Steps to reproduce the behavior:
NOTE: failure is more rare than success -- this depends on the reddit submissions returned by the Reddit API queries.

  1. Configure DJ-Tools with the appropriate options to run the Spotify playlist builder (SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET, SPOTIFY_REDIRECT_URI, SPOTIFY_USERNAME, AUTO_PLAYLIST_SUBREDDITS, AUTO_PLAYLIST_FUZZ_RATIO, AUTO_PLAYLIST_SUBREDDIT_LIMIT, REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, REDDIT_USER_AGENT)
  2. Run DJ-Tools with the option that enables the Spotify playlist builder: djtools --auto_playlist_update

Expected behavior
The query strings for the Spotify API's search endpoint should be cleansed and formatted properly to avoid errors. Any exceptions should be logged and handled rather than being raised.

Desktop (please complete the following information):

  • Version dj-beatcloud==2.3.0b6 (this has been happening since the feature was introduced)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions