Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except (ConnectionError, socket.timeout, PyiCloudAPIResponseError) as ex:
if "Invalid global session" in str(ex):
logger.tqdm_write(
"Session error, re-authenticating...",
logging.ERROR)
if retries > 0:
# If the first reauthentication attempt failed,
# start waiting a few seconds before retrying in case
# there are some issues with the Apple servers
time.sleep(constants.WAIT_SECONDS)
icloud.authenticate()
else:
logger.tqdm_write(
"Error downloading %s, retrying after %d seconds..."
% (photo.filename, constants.WAIT_SECONDS),
logging.ERROR,
)
time.sleep(constants.WAIT_SECONDS)
except IOError:
logger.error(
"IOError while writing file to %s! "
"You might have run out of disk space, or the file "
"might be too large for your OS. "
"Skipping this file...", download_path
)
break
else:
logger.tqdm_write(
"Could not download %s! Please try again later." % photo.filename
)
"Could not find URL to download %s for size %s!"
% (photo.filename, size),
logging.ERROR,
)
break
except (ConnectionError, socket.timeout, PyiCloudAPIResponseError) as ex:
if "Invalid global session" in str(ex):
logger.tqdm_write(
"Session error, re-authenticating...",
logging.ERROR)
if retries > 0:
# If the first reauthentication attempt failed,
# start waiting a few seconds before retrying in case
# there are some issues with the Apple servers
time.sleep(constants.WAIT_SECONDS)
icloud.authenticate()
else:
logger.tqdm_write(
"Error downloading %s, retrying after %d seconds..."
% (photo.filename, constants.WAIT_SECONDS),
logging.ERROR,
)
time.sleep(constants.WAIT_SECONDS)
except IOError:
logger.error(
"IOError while writing file to %s! "
"You might have run out of disk space, or the file "
"might be too large for your OS. "
"Skipping this file...", download_path
def photos_exception_handler(ex, retries):
"""Handles session errors in the PhotoAlbum photos iterator"""
if "Invalid global session" in str(ex):
if retries > constants.MAX_RETRIES:
logger.tqdm_write(
"iCloud re-authentication failed! Please try again later."
)
raise ex
logger.tqdm_write(
"Session error, re-authenticating...",
logging.ERROR)
if retries > 1:
# If the first reauthentication attempt failed,
# start waiting a few seconds before retrying in case
# there are some issues with the Apple servers
time.sleep(constants.WAIT_SECONDS)
icloud.authenticate()