For some reason, the library im using to interact with Spotify will retry when it's being rate limited on GET requests, but not on POST requests, which can break the experience for users. Per the logs:
2020-04-01T14:59:03.059990+00:00 app[web.1]: ERROR: SpotifyException: http status: 429, code:-1 - :
2020-04-01T14:59:03.059991+00:00 app[web.1]: API rate limit exceeded
2020-04-01T14:59:03.059992+00:00 app[web.1]: Traceback (most recent call last):
2020-04-01T14:59:03.059992+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/spotipy/client.py", line 164, in _internal_call
2020-04-01T14:59:03.059993+00:00 app[web.1]: r.raise_for_status()
2020-04-01T14:59:03.059993+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
2020-04-01T14:59:03.059994+00:00 app[web.1]: raise HTTPError(http_error_msg, response=self)
2020-04-01T14:59:03.059997+00:00 app[web.1]: requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url:
2020-04-01T14:59:03.059997+00:00 app[web.1]:
2020-04-01T14:59:03.059998+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-04-01T14:59:03.059998+00:00 app[web.1]:
2020-04-01T14:59:03.059998+00:00 app[web.1]: Traceback (most recent call last):
2020-04-01T14:59:03.059999+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
2020-04-01T14:59:03.059999+00:00 app[web.1]: rv = self.dispatch_request()
2020-04-01T14:59:03.059999+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
2020-04-01T14:59:03.060000+00:00 app[web.1]: return self.view_functionsrule.endpoint
2020-04-01T14:59:03.060000+00:00 app[web.1]: File "/app/src/spotify_app.py", line 97, in generate_recs
2020-04-01T14:59:03.060000+00:00 app[web.1]: sp.generate_recommendations(rec_spec)
2020-04-01T14:59:03.060001+00:00 app[web.1]: File "/app/src/spotipy_wrapper.py", line 156, in generate_recommendations
2020-04-01T14:59:03.060001+00:00 app[web.1]: self.create_playlist(rec_track_ids, rec_spec.playlist_name, rec_spec.seed)
2020-04-01T14:59:03.060001+00:00 app[web.1]: File "/app/src/spotipy_wrapper.py", line 151, in create_playlist
2020-04-01T14:59:03.060002+00:00 app[web.1]: self.sp.user_playlist_add_tracks(user=self.username, playlist_id=playlist_id, tracks=chunk)
2020-04-01T14:59:03.060002+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/spotipy/client.py", line 595, in user_playlist_add_tracks
2020-04-01T14:59:03.060002+00:00 app[web.1]: position=position,
2020-04-01T14:59:03.060002+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/spotipy/client.py", line 211, in _post
2020-04-01T14:59:03.060002+00:00 app[web.1]: return self._internal_call("POST", url, payload, kwargs)
2020-04-01T14:59:03.060003+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/spotipy/client.py", line 174, in _internal_call
2020-04-01T14:59:03.060003+00:00 app[web.1]: headers=r.headers,
2020-04-01T14:59:03.060003+00:00 app[web.1]: spotipy.client.SpotifyException: http status: 429, code:-1 - :
2020-04-01T14:59:03.060004+00:00 app[web.1]: API rate limit exceeded
looks like I'll have to add custom retries when doing POSTs such as creating a playlist for a user or adding tracks to it
For some reason, the library im using to interact with Spotify will retry when it's being rate limited on GET requests, but not on POST requests, which can break the experience for users. Per the logs:
2020-04-01T14:59:03.059990+00:00 app[web.1]: ERROR: SpotifyException: http status: 429, code:-1 -:
2020-04-01T14:59:03.059991+00:00 app[web.1]: API rate limit exceeded
2020-04-01T14:59:03.059992+00:00 app[web.1]: Traceback (most recent call last):
2020-04-01T14:59:03.059992+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/spotipy/client.py", line 164, in _internal_call
2020-04-01T14:59:03.059993+00:00 app[web.1]: r.raise_for_status()
2020-04-01T14:59:03.059993+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
2020-04-01T14:59:03.059994+00:00 app[web.1]: raise HTTPError(http_error_msg, response=self)
2020-04-01T14:59:03.059997+00:00 app[web.1]: requests.exceptions.HTTPError: 429 Client Error: Too Many Requests for url:
2020-04-01T14:59:03.059997+00:00 app[web.1]:
2020-04-01T14:59:03.059998+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-04-01T14:59:03.059998+00:00 app[web.1]:
2020-04-01T14:59:03.059998+00:00 app[web.1]: Traceback (most recent call last):
2020-04-01T14:59:03.059999+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1949, in full_dispatch_request
2020-04-01T14:59:03.059999+00:00 app[web.1]: rv = self.dispatch_request()
2020-04-01T14:59:03.059999+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1935, in dispatch_request
2020-04-01T14:59:03.060000+00:00 app[web.1]: return self.view_functionsrule.endpoint
2020-04-01T14:59:03.060000+00:00 app[web.1]: File "/app/src/spotify_app.py", line 97, in generate_recs
2020-04-01T14:59:03.060000+00:00 app[web.1]: sp.generate_recommendations(rec_spec)
2020-04-01T14:59:03.060001+00:00 app[web.1]: File "/app/src/spotipy_wrapper.py", line 156, in generate_recommendations
2020-04-01T14:59:03.060001+00:00 app[web.1]: self.create_playlist(rec_track_ids, rec_spec.playlist_name, rec_spec.seed)
2020-04-01T14:59:03.060001+00:00 app[web.1]: File "/app/src/spotipy_wrapper.py", line 151, in create_playlist
2020-04-01T14:59:03.060002+00:00 app[web.1]: self.sp.user_playlist_add_tracks(user=self.username, playlist_id=playlist_id, tracks=chunk)
2020-04-01T14:59:03.060002+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/spotipy/client.py", line 595, in user_playlist_add_tracks
2020-04-01T14:59:03.060002+00:00 app[web.1]: position=position,
2020-04-01T14:59:03.060002+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/spotipy/client.py", line 211, in _post
2020-04-01T14:59:03.060002+00:00 app[web.1]: return self._internal_call("POST", url, payload, kwargs)
2020-04-01T14:59:03.060003+00:00 app[web.1]: File "/usr/local/lib/python3.7/site-packages/spotipy/client.py", line 174, in _internal_call
2020-04-01T14:59:03.060003+00:00 app[web.1]: headers=r.headers,
2020-04-01T14:59:03.060003+00:00 app[web.1]: spotipy.client.SpotifyException: http status: 429, code:-1 - :
2020-04-01T14:59:03.060004+00:00 app[web.1]: API rate limit exceeded
looks like I'll have to add custom retries when doing POSTs such as creating a playlist for a user or adding tracks to it