Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 3 additions & 13 deletions src/icloudpd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
from icloudpd.xmp_sidecar import generate_xmp_file
from pyicloud_ipd.base import PyiCloudService
from pyicloud_ipd.exceptions import (
PyiCloudAPIResponseException,
PyiCloudServiceNotActivatedException,
PyiCloudServiceUnavailableException,
)
from pyicloud_ipd.file_match import FileMatchPolicy
from pyicloud_ipd.raw_policy import RawTreatmentPolicy
Expand Down Expand Up @@ -1503,18 +1503,8 @@ def should_break(counter: Counter) -> bool:
)
else:
pass
except PyiCloudAPIResponseException as error:
if error.code == "503":
logger.info("Apple iCloud is temporary refusing to serve icloudpd")
# it not watching then return error
if not watch_interval:
return 1
else:
pass
else:
raise
except PyiCloudServiceNotActivatedException as error:
logger.info(error.reason)
except (PyiCloudServiceNotActivatedException, PyiCloudServiceUnavailableException) as error:
logger.info(error)
# it not watching then return error
if not watch_interval:
return 1
Expand Down
2 changes: 0 additions & 2 deletions src/pyicloud_ipd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ def encode(self) -> bytes:
if response.status_code == 401:
raise PyiCloudAPIResponseException(response.text, str(response.status_code))
except PyiCloudAPIResponseException as error:
if error.code == "503":
raise
msg = "Failed to initiate srp authentication."
raise PyiCloudFailedLoginException(msg, error) from error

Expand Down
3 changes: 3 additions & 0 deletions src/pyicloud_ipd/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class PyiCloudServiceNotActivatedException(PyiCloudAPIResponseException):
"""iCloud service not activated exception."""
pass

class PyiCloudServiceUnavailableException(PyiCloudException):
"""iCloud service not available (503)"""
pass

# Login
class PyiCloudFailedLoginException(PyiCloudException):
Expand Down
7 changes: 2 additions & 5 deletions src/pyicloud_ipd/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
PyiCloud2SARequiredException,
PyiCloudServiceNotActivatedException,
)
from pyicloud_ipd.utils import throw_on_503

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -63,17 +64,13 @@ def request(self, method: str, url, **kwargs): # type: ignore
kwargs.pop("retried", None)
if "timeout" not in kwargs and self.service.http_timeout is not None:
kwargs["timeout"] = self.service.http_timeout
response = super().request(method, url, **kwargs)
response = throw_on_503(super().request(method, url, **kwargs))

content_type = response.headers.get("Content-Type", "").split(";")[0]
json_mimetypes = ["application/json", "text/json"]

request_logger.debug(response.headers)

if response.status_code == 503:
api_error = PyiCloudAPIResponseException(response.reason, str(response.status_code))
raise api_error

for header, value in HEADER_DATA.items():
if response.headers.get(header):
session_arg = value
Expand Down
9 changes: 8 additions & 1 deletion src/pyicloud_ipd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from typing import Dict, Optional, Sequence
import typing
import keyring
from requests import Response

from pyicloud_ipd.asset_version import AssetVersion
from pyicloud_ipd.version_size import AssetVersionSize, VersionSize

from .exceptions import PyiCloudNoStoredPasswordAvailableException
from .exceptions import PyiCloudNoStoredPasswordAvailableException, PyiCloudServiceUnavailableException

KEYRING_SYSTEM = 'pyicloud://icloud-password'

Expand Down Expand Up @@ -135,3 +136,9 @@ def disambiguate_filenames(_versions: Dict[VersionSize, AssetVersion], _sizes:Se


return _results

def throw_on_503(response: Response) -> Response:
if response.status_code == 503:
raise PyiCloudServiceUnavailableException("Apple iCloud is temporary refusing to serve icloudpd")
else:
return response
Loading