Skip to content

Commit

Permalink
refresh tokens on 429 response codes
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelljkotler committed May 6, 2024
1 parent bfbed2a commit 977a5a2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
---------

4.1.1
~~~~~
* Refresh tokens on 429 response codes

4.1.0
~~~~~
* Add `revision_control` as an allowed upload parameter.
Expand Down
5 changes: 4 additions & 1 deletion documentcloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ def _request(self, method, url, raise_error=True, **kwargs):
method, url, timeout=self.timeout, **kwargs
)
logger.debug("response: %s - %s", response.status_code, response.content)
if response.status_code == requests.codes.FORBIDDEN and set_tokens:
if (
response.status_code in [requests.codes.FORBIDDEN, requests.codes.TOO_MANY]
and set_tokens
):
self._set_tokens()
# track set_tokens to not enter an infinite loop
kwargs["set_tokens"] = False
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="python-documentcloud",
version="4.1.0",
version="4.1.1",
description="A simple Python wrapper for the DocumentCloud API",
author="Mitchell Kotler",
author_email="[email protected]",
Expand Down

0 comments on commit 977a5a2

Please sign in to comment.