Skip to content

Commit 2dcb35c

Browse files
Retry on POST/PUT and 429 to handle rate limit errors automatically
1 parent f957343 commit 2dcb35c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

replicate/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ def __init__(self, api_token=None) -> None:
3232
retries = Retry(
3333
total=5,
3434
backoff_factor=2,
35-
# Only retry on GET so we don't unintionally mutute data
36-
method_whitelist=["GET"],
35+
# TODO: Only retry on GET so we don't unintionally mutute data
36+
method_whitelist=["GET", "POST", "PUT"],
3737
# https://support.cloudflare.com/hc/en-us/articles/115003011431-Troubleshooting-Cloudflare-5XX-errors
38-
status_forcelist=[500, 502, 503, 504, 520, 521, 522, 523, 524, 526, 527],
38+
status_forcelist=[429, 500, 502, 503, 504, 520, 521, 522, 523, 524, 526, 527],
3939
)
40+
4041
self.session.mount("http://", HTTPAdapter(max_retries=retries))
4142
self.session.mount("https://", HTTPAdapter(max_retries=retries))
4243

0 commit comments

Comments
 (0)