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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- chore: bump min python version 3.9->3.10
- fix: iCloud clean up with `--keep-icloud-recent-days` does not respect `--skip-*` params [#1180](https://github.com/icloud-photos-downloader/icloud_photos_downloader/issues/1180)
- chore: replace build & test platform from retired windows-2019 to windows-2025
- Service Temporary Unavailable responses are less ambiguous [#1078](https://github.com/icloud-photos-downloader/icloud_photos_downloader/issues/1078)

## 1.28.1 (2025-06-08)

Expand Down
2 changes: 2 additions & 0 deletions src/pyicloud_ipd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ def encode(self) -> bytes:
if response.status_code == 401:
raise PyiCloudAPIResponseException(response.text, str(response.status_code))
except PyiCloudAPIResponseException as error:
if response.status_code == 503:
raise
msg = "Failed to initiate srp authentication."
raise PyiCloudFailedLoginException(msg, error) from error

Expand Down
5 changes: 5 additions & 0 deletions src/pyicloud_ipd/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def request(self, method: str, url, **kwargs): # type: ignore

request_logger.debug(response.headers)

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

for header, value in HEADER_DATA.items():
if response.headers.get(header):
session_arg = value
Expand Down
28 changes: 28 additions & 0 deletions tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,34 @@ def test_non_2fa(self) -> None:

self.assertTrue(cass.all_played)

def test_failed_auth_503(self) -> None:
base_dir = os.path.join(self.fixtures_path, inspect.stack()[0][3])
cookie_dir = os.path.join(base_dir, "cookie")

for dir in [base_dir, cookie_dir]:
recreate_path(dir)

with vcr.use_cassette(os.path.join(self.vcr_path, "failed_auth_503.yml")): # noqa: SIM117
runner = CliRunner(env={"CLIENT_ID": "EC5646DE-9423-11E8-BF21-14109FE0B321"})
result = runner.invoke(
main,
[
"--username",
"jdoe@gmail.com",
"--password",
"password1",
"--no-progress-bar",
"--cookie-directory",
cookie_dir,
"--auth-only",
],
)
self.assertNotIn(
"ERROR Failed to login with srp, falling back to old raw password authentication.",
self._caplog.text,
)
self.assertIn("ERROR Service Temporary Unavailable (503)", self._caplog.text)
assert result.exit_code == 1

class _TrustedDevice(NamedTuple):
id: int
Expand Down
48 changes: 48 additions & 0 deletions tests/vcr_cassettes/failed_auth_503.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
interactions:
- request:
body: !!python/unicode '{"accountName": "whatever_username", "protocols": ["s2k", "s2k_fo"]}'
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: ['keep-alive']
Content-Length: ['98']
Content-Type: ['application/json']
Origin: ['https://www.icloud.com']
Referer: ['https://www.icloud.com/']
User-Agent: ['Opera/9.52 (X11; Linux i686; U; en)']
X-Apple-OAuth-Client-Id: ['d39ba9916b7251055b22c7f910e2ea796ee65e98b2ddecea8f5dde8d9d1a815d']
X-Apple-OAuth-Client-Type: ['firstPartyAuth']
X-Apple-OAuth-Redirect-URI: ['https://www.icloud.com']
X-Apple-OAuth-Require-Grant-Code: ['true']
X-Apple-OAuth-Response-Mode: ['web_message']
X-Apple-OAuth-Response-Type: ['code']
X-Apple-OAuth-State: ['EC5646DE-9423-11E8-BF21-14109FE0B321']
X-Apple-Widget-Key: ['d39ba9916b7251055b22c7f910e2ea796ee65e98b2ddecea8f5dde8d9d1a815d']
method: POST
uri: https://idmsa.apple.com/appleauth/auth/signin/init
response:
body: {string: 'Service Temporary Unavailable'}
headers:
Cache-Control:
- 'no-cache'
- 'no-store'
Connection: ['keep-alive']
Content-Type: ['text/html;charset=UTF-8']
Date: ['Fri, 15 Dec 2023 17:28:03 GMT']
Pragma: ['no-cache']
Referrer-Policy: ['origin']
Server: ['Apple']
Strict-Transport-Security: ['max-age=31536000; includeSubDomains; preload']
Transfer-Encoding: ['chunked']
X-Apple-I-Request-ID: ['12345678-1234-1234-1234-123456789012']
X-BuildVersion: ['R4_1']
X-Content-Type-Options: ['nosniff']
X-FRAME-OPTIONS: ['DENY']
X-XSS-Protection: ['1; mode=block']
content-length: ['29']
scnt: ['scnt-1234567890']
vary: ['accept-encoding']
status:
code: 503
message: 'Service Temporary Unavailable'
version: 1
Loading