Skip to content

Commit 5ddd760

Browse files
fix: Requests resulting in 503 Service Unavailable errors are now retried.
1 parent a68c8fd commit 5ddd760

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

CHANGELOG.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99
### Added
10-
* Add formality options `'prefer_less'` and `'prefer_more'`.
10+
* Add formality options `'PREFER_LESS'` and `'PREFER_MORE'`.
11+
### Changed
12+
* Requests resulting in `503 Service Unavailable` errors are now retried.
13+
Attempting to download a document before translation is completed will now
14+
wait and retry (up to 5 times by default), rather than raising an exception.
1115

1216

1317
## [1.10.0] - 2022-09-09
1418
### Added
1519
* New language available: Ukrainian (`'uk'`). Add language code constant and tests.
1620

1721
Note: older library versions also support new languages, this update only adds new code constant.
18-
* Add new `Formality` options: `PREFER_MORE` and `PREFER_LESS`.
1922
### Changed
2023
* Add note and workaround to README about Poetry error on Ubuntu 22.04.
2124
* Pull request [#48](https://github.com/DeepLcom/deepl-python/pull/48)

deepl/http_client.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ def _should_retry(self, response, exception, num_retries):
198198
return exception.should_retry
199199

200200
status_code, _ = response
201-
# Retry on Too-Many-Requests error and internal errors except
202-
# Service-Unavailable errors
201+
# Retry on Too-Many-Requests error and internal errors
203202
return status_code == http.HTTPStatus.TOO_MANY_REQUESTS or (
204203
status_code >= http.HTTPStatus.INTERNAL_SERVER_ERROR
205-
and status_code != http.HTTPStatus.SERVICE_UNAVAILABLE
206204
)

tests/test_translate_document.py

-7
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,6 @@ def test_translate_document_low_level(
181181
status = translator.translate_document_get_status(handle)
182182
assert status.ok and not status.done
183183

184-
# Calling download() before document is ready will fail
185-
with pytest.raises(
186-
deepl.DocumentNotReadyException, match="Document not ready"
187-
):
188-
with open(output_document_path, "wb") as output_file:
189-
translator.translate_document_download(handle, output_file)
190-
191184
# Test recreating a document handle from id & key
192185
doc_id, doc_key = handle.document_id, handle.document_key
193186
del handle

0 commit comments

Comments
 (0)