[PR #457] [MERGED] Retries For All Endpoints #904

Closed
opened 2026-02-28 00:02:30 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/spotipy-dev/spotipy/pull/457
Author: @Beahmer89
Created: 3/24/2020
Status: Merged
Merged: 3/29/2020
Merged by: @stephanebruckert

Base: masterHead: improvements


📝 Commits (5)

  • eb4b4d6 test_improvements - Add init.py files to tests dirs so you can run all tests
  • 6469e9d test_improvements - added helpers file, restructured tests to work without previous data and to be grouped with api type
  • 5080763 http_retries - Implement Retry for all requests
  • d23883f Readme - Update README with contributing info
  • a4fdea7 PR Feedback - Added CONTRIBUTING.md, fixed README, fixed test

📊 Changes

9 files changed (+388 additions, -334 deletions)

View changed files

CONTRIBUTING.md (+18 -0)
📝 requirements.txt (+1 -1)
📝 spotipy/client.py (+69 -48)
tests/__init__.py (+0 -0)
tests/helpers.py (+19 -0)
tests/integration/__init__.py (+0 -0)
📝 tests/integration/test_non_user_endpoints.py (+6 -11)
📝 tests/integration/test_user_endpoints.py (+275 -274)
tests/unit/__init__.py (+0 -0)

📄 Description

Purpose of PR
I was looking through open issues when I noticed issue 347. I noticed that there was a pull request up for this here. The solution works with adding it to each method function, but it would be cleaner if moved into _internal_call. Also the logic could be cleaned up as well, so I decided to make a PR.

This PR is to allow Retries for all method calls by utilizing urllib3.Retry() to allow the following:

  • Setting a default list of status codes to retry on or list the user define a list
  • Default/user defined number of retries to allow
  • Default/user defined backoff value for how long the requests should wait before retrying.
    • {backoff factor} * (2 ** ({number of total retries} - 1)) found in urllib3 docs

By doing this is, it cleans up the retry logic a lot that is already implemented in the code

What Was Done

  • Setup function in client to build the the new requests session with the urllib3.Retry()
  • Restructured _internal_call
    • Now catching specific exceptions not just generic ones
    • No longer using request call as context manager
    • Calling raise for error after the request call and then decoding the response to json() all in one try...except
  • Updated by using appropriate unittest methods that make things more clear rather than just using assertTrue and assertFalse
    • this was only done in the client files
  • Reorganized client tests to be grouped according to their Api defined here
  • Updated README to include how one could contribute to spotipy and what variables they need to have set for the tests to run.
  • Added requirement dependency for nose since it wasnt already defined in requirements.txt

Other Things to Note

  • By default I disable retries for the session/adapter for read errors and set it to False like they do by default in the requests library here

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/spotipy-dev/spotipy/pull/457 **Author:** [@Beahmer89](https://github.com/Beahmer89) **Created:** 3/24/2020 **Status:** ✅ Merged **Merged:** 3/29/2020 **Merged by:** [@stephanebruckert](https://github.com/stephanebruckert) **Base:** `master` ← **Head:** `improvements` --- ### 📝 Commits (5) - [`eb4b4d6`](https://github.com/spotipy-dev/spotipy/commit/eb4b4d6c957f450f34019df7604ce07fd45d44e1) test_improvements - Add __init__.py files to tests dirs so you can run all tests - [`6469e9d`](https://github.com/spotipy-dev/spotipy/commit/6469e9dab9839221e9c6e8d185dc6b1e02de0ea5) test_improvements - added helpers file, restructured tests to work without previous data and to be grouped with api type - [`5080763`](https://github.com/spotipy-dev/spotipy/commit/5080763acf609b2897048f21926a9563fc98139e) http_retries - Implement Retry for all requests - [`d23883f`](https://github.com/spotipy-dev/spotipy/commit/d23883f95be2185ba31813704122d991039997de) Readme - Update README with contributing info - [`a4fdea7`](https://github.com/spotipy-dev/spotipy/commit/a4fdea76e187f27f0e6b038ab25ccabb6429b224) PR Feedback - Added CONTRIBUTING.md, fixed README, fixed test ### 📊 Changes **9 files changed** (+388 additions, -334 deletions) <details> <summary>View changed files</summary> ➕ `CONTRIBUTING.md` (+18 -0) 📝 `requirements.txt` (+1 -1) 📝 `spotipy/client.py` (+69 -48) ➕ `tests/__init__.py` (+0 -0) ➕ `tests/helpers.py` (+19 -0) ➕ `tests/integration/__init__.py` (+0 -0) 📝 `tests/integration/test_non_user_endpoints.py` (+6 -11) 📝 `tests/integration/test_user_endpoints.py` (+275 -274) ➕ `tests/unit/__init__.py` (+0 -0) </details> ### 📄 Description **Purpose of PR** I was looking through open issues when I noticed issue [347](https://github.com/plamere/spotipy/issues/347). I noticed that there was a pull request up for this [here](https://github.com/plamere/spotipy/pull/271). The solution works with adding it to each method function, but it would be cleaner if moved into `_internal_call`. Also the logic could be cleaned up as well, so I decided to make a PR. This PR is to allow Retries for all method calls by utilizing `urllib3.Retry()` to allow the following: - Setting a default list of status codes to retry on or list the user define a list - Default/user defined number of retries to allow - Default/user defined backoff value for how long the requests should wait before retrying. - `{backoff factor} * (2 ** ({number of total retries} - 1))` found in [urllib3 docs](https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html) By doing this is, it cleans up the retry logic a lot that is already implemented in the code **What Was Done** - Setup function in client to build the the new requests session with the urllib3.Retry() - Restructured `_internal_call` - Now catching specific exceptions not just generic ones - No longer using request call as context manager - Calling raise for error after the request call and then decoding the response to json() all in one try...except - Updated by using appropriate unittest methods that make things more clear rather than just using assertTrue and assertFalse - this was only done in the client files - Reorganized client tests to be grouped according to their Api defined [here](https://developer.spotify.com/documentation/web-api/reference-beta/#category-browse) - Updated README to include how one could contribute to spotipy and what variables they need to have set for the tests to run. - Added requirement dependency for nose since it wasnt already defined in requirements.txt **Other Things to Note** - By default I disable retries for the session/adapter for read errors and set it to `False` like they do by default in the requests library [here](https://github.com/psf/requests/blob/master/requests/adapters.py#L117) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-28 00:02:30 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#904
No description provided.