Skip to content

Commit 1bc03ca

Browse files
retry zero times
1 parent adfccc5 commit 1bc03ca

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/icloudpd/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,8 @@ def session_error_handle_builder(
12331233
) -> None:
12341234
"""Handles session errors in the PhotoAlbum photos iterator"""
12351235
if "Invalid global session" in str(ex):
1236+
if constants.MAX_RETRIES == 0:
1237+
logger.error("Session error, re-authenticating...")
12361238
if attempt > constants.MAX_RETRIES:
12371239
logger.error("iCloud re-authentication failed. Please try again later.")
12381240
raise ex

src/icloudpd/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
from typing import Final
44

55
# For retrying connection after timeouts and errors
6-
MAX_RETRIES: Final[int] = 4
6+
MAX_RETRIES: Final[int] = 0
77
WAIT_SECONDS: Final[int] = 5

src/icloudpd/download.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def download_media(
112112
if not mkdirs_local(logger, download_path):
113113
return False
114114

115-
for retries in range(constants.MAX_RETRIES):
115+
retries = 0
116+
while True:
116117
try:
117118
photo_response = photo.download(version.url)
118119
if photo_response:
@@ -134,6 +135,9 @@ def download_media(
134135

135136
icloud.authenticate()
136137
else:
138+
# short circuiting 0 retries
139+
if retries == constants.MAX_RETRIES:
140+
break
137141
# you end up here when p.e. throttling by Apple happens
138142
wait_time = (retries + 1) * constants.WAIT_SECONDS
139143
logger.error(
@@ -150,7 +154,10 @@ def download_media(
150154
download_path,
151155
)
152156
break
153-
else:
157+
retries = retries + 1
158+
if retries >= constants.MAX_RETRIES:
159+
break
160+
if retries >= constants.MAX_RETRIES:
154161
logger.error(
155162
"Could not download %s. Please try again later.",
156163
photo.filename,

0 commit comments

Comments
 (0)