Skip to content

Commit

Permalink
Retry HTTP calls on any error occuring during the request, not only b…
Browse files Browse the repository at this point in the history
…ad HTTP status code
  • Loading branch information
benoit74 committed May 14, 2024
1 parent 4824b80 commit b79554c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Change log level from ERROR to WARNING for missing translations (#197)
- Fix HTTP retries to consider any HTTP failure, not only bad HTTP status code (#162)

## [3.0.0] - 2024-04-19

Expand Down
24 changes: 12 additions & 12 deletions src/ted2zim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ def request_url(url, json_data=None):
url = f"{BASE_URL}playlists/57/björk_6_talks_that_are_music"
max_attempts, attempt = 5, 1
while True:
time.sleep(1) # delay requests
if json_data:
req = requests.post(
url,
headers={"User-Agent": "Mozilla/5.0"},
json=json_data,
timeout=REQUESTS_TIMEOUT,
)
else:
req = requests.get(
url, headers={"User-Agent": "Mozilla/5.0"}, timeout=REQUESTS_TIMEOUT
)
try:
time.sleep(1) # delay requests
if json_data:
req = requests.post(
url,
headers={"User-Agent": "Mozilla/5.0"},
json=json_data,
timeout=REQUESTS_TIMEOUT,
)
else:
req = requests.get(
url, headers={"User-Agent": "Mozilla/5.0"}, timeout=REQUESTS_TIMEOUT
)
req.raise_for_status()
return req
except Exception as exc:
Expand Down

0 comments on commit b79554c

Please sign in to comment.