Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry downloads that fail with ConnectionError #134

Merged
merged 2 commits into from
Jan 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/tinuous/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from pydantic import BaseModel, Field, validator
import requests
from requests.exceptions import ChunkedEncodingError
from requests.exceptions import ChunkedEncodingError, ConnectionError as ReqConError

from .util import delay_until, expand_template, log, sanitize_pathname

Expand Down Expand Up @@ -103,17 +103,17 @@ def get(self, path: str, **kwargs: Any) -> requests.Response:
def download(self, path: str, filepath: Path) -> None:
i = 0
while True:
r = self.get(path, stream=True)
try:
try:
r = self.get(path, stream=True)
with filepath.open("wb") as fp:
for chunk in r.iter_content(chunk_size=8192):
fp.write(chunk)
except ChunkedEncodingError as e:
except (ChunkedEncodingError, ReqConError) as e:
if i < self.MAX_RETRIES:
log.warning(
"Download from %s interrupted: %s; waiting & retrying",
r.request.url,
"Download of %s interrupted: %s; waiting & retrying",
path,
str(e),
)
i += 1
Expand Down