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

iCloud 3 hangs indefinitely on Apple account sign in #426

Open
andrew-kennedy opened this issue Feb 14, 2025 · 26 comments
Open

iCloud 3 hangs indefinitely on Apple account sign in #426

andrew-kennedy opened this issue Feb 14, 2025 · 26 comments

Comments

@andrew-kennedy
Copy link

I was having issues where iCloud 3 hangs indefinitely upon sign in, and I tried to fully uninstall and delete its .storage directory and such and it still will not sign in upon reinstall and HA restart.

This is on version 3.1.5.1 released a few days ago. I don't see any errors in the logs, but I haven't turned in debug logs yet. Is there any additional "deletion" step I can take besides deleting the .storage directories for icloud3?

@gcobb321
Copy link
Owner

I did find one problem where an unknown Mobile App device in the config would create an error.

See here for a patch that should fix that.

If that does not work, see if there are any errors related to iCloud3 at Settings > System > Logs. You can turn on Debug logs on Configure > Tools. Restart and email icloud3.log to geekstergary@gmail.com

Tools also has some maintenance items so you do not have to fiddle with the .storage config files.

@andrew-kennedy
Copy link
Author

andrew-kennedy commented Feb 15, 2025

When I try to add an apple account after setting up from scratch, I get these logs:

2025-02-14 17:37:26.438 DEBUG (MainThread) [custom_components.icloud3] [config_flow…:5400] CONFIG  DATA_SOURCE (update_apple_acct) > UserInput-{'data_source': ['iCloud', 'MobApp'], 'apple_accts': '➤ ADD A NEW APPLE ACCOUNT'}, Errors-{'apple_accts': 'icloud_acct_not_set_up'}
2025-02-14 17:37:38.497 DEBUG (MainThread) [custom_components.icloud3] [config_flow…:2155] CONFIG  UPDATE_APPLE_ACCT (save_log_into_apple_acct) > UserInput-{'account_selected': '➤ ADD A NEW APPLE ACCOUNT', 'username': '<redacted>', 'password': '<redacted>', 'locate_all': True, 'url_suffix_china': False, 'icloud_server_endpoint_suffix': 'None', 'totp_key': ''}, Errors-None
2025-02-14 17:37:38.512 DEBUG (SyncWorker_10) [custom_components.icloud3] [pyicloud_ic3:0472] CONFIG  <redacted>, Initialize PyiCloud Service, Set up iCloud Location Services connection
2025-02-14 17:37:38.521 DEBUG (SyncWorker_10) [custom_components.icloud3] [pyicloud_ic3:0233] CONFIG  <redacted>, Validate Username/Password
2025-02-14 17:37:38.542 DEBUG (SyncWorker_10) [custom_components.icloud3] [pyicloud_ic3:0238] CONFIG  <redacted>, Method-TokenPW Session Token, Results-False
2025-02-14 17:37:38.556 DEBUG (SyncWorker_10) [custom_components.icloud3] [pyicloud_ses:0169] CONFIG
🔺 <redacted>, POST, REQUEST, VALIDATE_WITH_VERIFY_VIA_URL/289 ▲
❗   items={'url': 'setup.icloud.com/setup/authenticate/<redacted>', 'retry': 0, 'data': None, 'json': None}
❗   headers={'Authorization': 'Basic <redacted>'}
2025-02-14 17:38:40.148 DEBUG (SyncWorker_0) [custom_components.icloud3] [icloud3_main:1359] 🛑      HomeAsst Offline > Pause all tracking
2025-02-14 17:38:45.145 DEBUG (SyncWorker_9) [custom_components.icloud3] [pyicloud_ses:0354] CONFIG  Request  Internet Connection status (#1), Sent-17:38:45
2025-02-14 17:39:00.153 DEBUG (SyncWorker_5) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-15 secs ago
2025-02-14 17:39:15.140 DEBUG (SyncWorker_0) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-30 secs ago
2025-02-14 17:39:30.144 DEBUG (SyncWorker_2) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-45 secs ago
2025-02-14 17:39:45.144 DEBUG (SyncWorker_5) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-1 min ago
2025-02-14 17:40:00.142 DEBUG (SyncWorker_5) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-1 min ago
2025-02-14 17:40:15.142 DEBUG (SyncWorker_0) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-2 mins ago
2025-02-14 17:40:30.145 DEBUG (SyncWorker_2) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-2 mins ago
2025-02-14 17:40:45.141 DEBUG (SyncWorker_0) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-2 mins ago
2025-02-14 17:41:00.145 DEBUG (SyncWorker_8) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-2 mins ago
2025-02-14 17:41:15.146 DEBUG (SyncWorker_3) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-2 mins ago
2025-02-14 17:41:30.144 DEBUG (SyncWorker_7) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-3 mins ago
2025-02-14 17:41:45.145 DEBUG (SyncWorker_2) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-3 mins ago
2025-02-14 17:42:00.146 DEBUG (SyncWorker_8) [custom_components.icloud3] [pyicloud_ic3:0196] CONFIG  Wait for Internet Connection response, Sent-3 mins ago
2025-02-14 17:43:25.259 DEBUG (SyncWorker_0) [custom_components.icloud3] [icloud3_main:1412] 🛑      HomeAsst Back Online > Resume tracking
2025-02-14 17:43:30.149 DEBUG (SyncWorker_9) [custom_components.icloud3] [icloud3_main:1359] 🛑      HomeAsst Offline > Pause all tracking
2025-02-14 17:43:35.144 DEBUG (SyncWorker_0) [custom_components.icloud3] [pyicloud_ses:0354] CONFIG  Request  Internet Connection status (#1), Sent-17:43:35
2025-02-14 17:43:35.225 DEBUG (SyncWorker_0) [custom_components.icloud3] [pyicloud_ic3:0205] CONFIG  Received Internet Connection status, Available-True
2025-02-14 17:43:35.238 DEBUG (SyncWorker_0) [custom_components.icloud3] [icloud3_main:1412] 🛑      HomeAsst Back Online > Resume tracking
2025-02-14 17:43:40.144 DEBUG (SyncWorker_0) [custom_components.icloud3] [icloud3_main:1359] 🛑      HomeAsst Offline > Pause all tracking
2025-02-14 17:43:45.144 DEBUG (SyncWorker_1) [custom_components.icloud3] [pyicloud_ses:0354] CONFIG  Request  Internet Connection status (#1), Sent-17:43:45
2025-02-14 17:43:45.221 DEBUG (SyncWorker_1) [custom_components.icloud3] [pyicloud_ic3:0205] CONFIG  Received Internet Connection status, Available-True
2025-02-14 17:43:45.234 DEBUG (SyncWorker_1) [custom_components.icloud3] [icloud3_main:1412] 🛑      HomeAsst Back Online > Resume tracking

and so on, until it times out. The thing is, home assistant isn't offline. Every other internet-requiring integration works.

@andrew-kennedy
Copy link
Author

andrew-kennedy commented Feb 15, 2025

I downgraded to version 3.4.1 actually and see the same thing but without the back and forth internet connection response:

2025-02-14 18:37:15.866 DEBUG (MainThread) [custom_components.icloud3] [config_flow…:5293] CONFIG  DATA_SOURCE (update_apple_acct) > UserInput-{'data_source': ['iCloud', 'MobApp'], 'apple_accts': '➤ ADD A NEW APPLE ACCOUNT'}, Errors-{'apple_accts': 'icloud_acct_not_set_up'}
2025-02-14 18:37:25.652 DEBUG (MainThread) [custom_components.icloud3] [config_flow…:2078] CONFIG  UPDATE_APPLE_ACCT (save_log_into_apple_acct) > UserInput-{'account_selected': '➤ ADD A NEW APPLE ACCOUNT', 'username': '<redacted>', 'password': '<redacted>', 'totp_key': '', 'locate_all': True, 'url_suffix_china': False, 'icloud_server_endpoint_suffix': 'None'}, Errors-None
2025-02-14 18:37:25.672 DEBUG (SyncWorker_12) [custom_components.icloud3] [pyicloud_ic3:0408] CONFIG  <username_redacted>, Initialize PyiCloud Service, Set up iCloud Location Services connection
2025-02-14 18:37:25.702 DEBUG (SyncWorker_12) [custom_components.icloud3] [pyicloud_ic3:0204] CONFIG  <username_redacted>, Validate Username/Password
2025-02-14 18:37:25.718 DEBUG (SyncWorker_12) [custom_components.icloud3] [pyicloud_ic3:0209] CONFIG  <username_redacted>, Method-TokenPW Session Token, Results-False
2025-02-14 18:37:25.756 DEBUG (SyncWorker_12) [custom_components.icloud3] [pyicloud_ses:0164] CONFIG
🔺 <username_redacted>, POST, REQUEST, VALIDATE_WITH_VERIFY_VIA_URL/258 ▲
❗   items={'url': 'setup.icloud.com/setup/authenticate/<email_redacted>', 'retry': 0, 'data': None, 'json': None}
❗   headers={'Authorization': 'Basic <redacted>'}
2025-02-14 18:48:43.022 DEBUG (SyncWorker_12) [custom_components.icloud3] [pyicloud_ses:0239] CONFIG
🔻 <username_redacted>, POST, RESPONSE, VALIDATE_WITH_VERIFY_VIA_URL/258 ▼
❗   items={'code': 409, 'ok': False}
2025-02-14 18:48:43.029 DEBUG (SyncWorker_12) [custom_components.icloud3] [pyicloud_ic3:0214] CONFIG  <username_redacted>, Method-setup/authenticate URL, Results-True
2025-02-14 18:48:43.035 DEBUG (SyncWorker_12) [custom_components.icloud3] [pyicloud_ic3:0227] CONFIG  <username_redacted>, Validate Username/Password,  Method-setup/authenticate URL, Result-True

I'm thinking maybe something changed with apple's servers? I am easily able to sign in on iCloud web on the same machine running home assistant, so I don't think my IP address is getting rate limited or blocked or anything...

@gcobb321
Copy link
Owner

It probably was Apple went down and that generated a connection error message. iCloud3 will flag the internet down and pause tracking. It then tries to connect with Google at 8.8.8.8 and says the internet is back up when it gets a good response.

@gcobb321
Copy link
Owner

V3.1.4.1 handled connection issues differently without trying to see when it came back up. It would also hang on connection issues if the error occurred adding a new Apple account. That was a major change between 3.1.4 and 3.1.5. It also identified a connection error by the word ‘connection’ in the error message which missed about 10 other errors that are also related to the Internet being down.

@andrew-kennedy
Copy link
Author

I'm still not sure how to get it back up. I tried the patch for 3.1.5.1 that you linked in the other thread and still no luck and still the same error and same logs. Somehow seems it can't connect to apple's servers.

@gcobb321
Copy link
Owner

Set Debug logging on Configure > Tools
Restart HA
Try to add your Apple account again
Send me your icloud3.log file. Having just a snippet of it posted here will not help identify the problem. The file will show how everything is being set up.

Also see if there are errors related to iCloud3 in the HA logs at Settings > Systym > Logs

G

@TimMeisberger
Copy link

I just wanted to mention that I’ve been experiencing the same issue since yesterday. When I request a verification code, my Apple device displays one, but iCloud3 v3 remains stuck in the loading screen. If I close the iCloud3 v3 window and reopen it to enter the code, the issue persists—it stays in the loading screen again. How can I send you the log-file? To your email adress?

@gcobb321
Copy link
Owner

@TimMeisberger
Are errors related to iCloud3 in the HA logs at Settings > System > Logs
Setting the Log Level to Debug, restarting HA and trying it again will give me a lot more info.
Send the icloud3.log file to geekstergary@gmail.com

@gcobb321
Copy link
Owner

@TimMeisberger
I've gone through the log file and you have redacted a lot of things so it was hard to follow what was going on with your 3-apple accounts since you redacted them to all the same value. Also, you may have redacted 'icloud.com' which made it hard to see if there were any url problems.

In any case, when icloud3 starts it validates the username/password with a simple call to the apple authenticate url. I can see the message being sent but nothing is ever received back. Either Apple is not responding, there was an internet issue at the time when HA was being set up that cleared up later on.

Also, I can see some responses from Apple indicating the Browser is not trusted and the request to ask for a verification code is False

data.items={'hsaTrustedBrowser': False, 'hsaChallengeRequired': False}

Are using a hardware security key like a YubiKey?

I have just released v3.1.5.2b2 to handle some Apple Account issues. I do not think it will help but would like to download and install it to see if it does. It is on the iCloud3 Development Repo here.

Either download the icloud3.zip file or from HACS if you are subscribed to the iCloud3 Development site.

@andrew-kennedy
Copy link
Author

andrew-kennedy commented Feb 20, 2025

I enabled debug mode on 3.1.5.2b2, tried to sign in, had it hang and then fail, and this is my entire icloud3.log file contents:

02-19 08:09:37 [__init__…………:0153] _INIT_  Setting up iCloud3 v3.1.5.2b2
02-19 08:09:41 [restore_stat:0042] _INIT_  Invalid icloud3.restore_state File-/config/.storage/icloud3/restore_state
02-19 08:09:41 [restore_stat:0074] _INIT_  Creating iCloud3 Restore State File - /config/.storage/icloud3/restore_state
02-19 08:09:41 [pyicloud_ic3:0496] _INIT_  ********, Initialize PyiCloud Service, Set up iCloud Location Services connection
02-19 08:09:42 [pyicloud_ic3:0496] _INIT_  <redacted_username>, Initialize PyiCloud Service, Set up iCloud Location Services connection
02-19 08:09:42 [pyicloud_ic3:0236] _INIT_  <redacted_username>, Validate Username/Password
02-19 08:09:42 [pyicloud_ic3:0241] _INIT_  <redacted_username>, Method-TokenPW Session Token, Results-False
02-19 08:09:42 [pyicloud_ses:0169] _INIT_
🔺 <redacted_username>, POST, REQUEST, VALIDATE_WITH_VERIFY_VIA_URL/303 ▲
❗   items={'url': 'setup.icloud.com/setup/authenticate/<redacted_username>@', 'retry': 0, 'data': None, 'json': None}
❗   headers={'Authorization': 'Basic ……VjeQ=='}

Looks like the auth pages have moved maybe? 303 errors are strange here.

@kjake
Copy link

kjake commented Feb 20, 2025

Not to send anyone on a wild goose chase, but I experienced issues with login in the same time period and was able to resolve it myself. The problem ultimately turned out to be related to how I had configured IPv6 in my network.

The iCloud v3 add-in (or possibly Home Assistant itself) is doing Internet connectivity checks against Google (it seemed to be dns.google), and those were failing on my network due to blocking DoH. Once I resolved that, and disabled IPv6 on my HA system, I was able to authenticate to iCloud again. I was able to re-enable IPv6 on HA after fixing a routing/addressing issue on my Firewall.

This may be completely specific to my set-up, but I'm hoping it provides some inspiration for troubleshooting!

@andrew-kennedy
Copy link
Author

Hmm, so my ISP has misconfigured IPv6 so I can't access the IPv6 internet at all from within my network, despite using the correct prefix. But this has been the case for a year + while iCloudv3 worked the whole time until just recently. I do have seemingly working IPv6 within my network though, as matter/thread all work correctly.

@kjake
Copy link

kjake commented Feb 21, 2025

@andrew-kennedy my assumption is that this wouldn't be a problem unless the Home Assistant system is receiving IPv6 addresses in responses from DNS. At the very least, that could create delay until a failback to IPv4; however, my experience was that the add-in never failed back to IPv4 while my IPv6 network was experiencing routing issues (which I caused).

@gcobb321
Copy link
Owner

@andrew-kennedy @eking0421
iCloud3 does not get into IPv6 or IPv4 options. It uses the Python session modules for all network posts and requests and assumes that it handles everything.

However, when checking to see if it back up after receiving on of the errors, it tries to get a response from Google at 8.8.8.8.

Should that be changed to www.google.com instead?

@andrew-kennedy
Copy link
Author

I am able to ping 8.8.8.8 from my home assistant host (raspberry pi) so that's not the issue for me at least... I really don't know but perhaps the 303 is due to some regional change with Apple's auth in the US vs the UK? I never actually changed anything with iCloud3 besides updating to 3.1.5 and after that even a rollback wouldn't fix it, so I'm thinking this might be due to Apple not iCloud v3

@gcobb321
Copy link
Owner

Are you getting the 303 from this line in the log file ?

redacted_username>, POST, REQUEST, VALIDATE_WITH_VERIFY_VIA_URL/303 ▲

If so, the 303 is actually the line in the code that requested the data from Apple in the VALIDATE_WITH_VERIFY_VIA_URL function.

@andrew-kennedy
Copy link
Author

Oh, gotcha. Figured it might be an HTTP error code. My bad!

@andrew-kennedy
Copy link
Author

Is there any way to enable even more debug logging @gcobb321 ? I'm really missing having iCloud3 working but don't know how to gather any more information about why it's not working. All I have is the tiny log output I already posted here.

@andrew-kennedy
Copy link
Author

I just noticed that after deleting iCloud 3 and all its .storage folders and settings again and installing 3.1.6 beta, it still errors on sign in but then 5 minutes later my iPhone gets the verification code pop up. Can't use it as iCloud 3 has already timed out or errored but it does come through

@gcobb321
Copy link
Owner

You can set the log level on Configure > Tools.

There are 3 levels of debugging - Info, Debug, RawData. They are described here. The sample I images are outdated b but their description is still valid.

@gcobb321
Copy link
Owner

I added an additional log_exception message to the routine that catches the Internet Connection error to get a detailed message in the logs on the cause.

You should already see an error message with the reason in the Event Log.

Unzip this into the icloud3/support directory and restart HA

patch-v3.1.6-pyicloud_session.zip

@andrew-kennedy
Copy link
Author

andrew-kennedy commented Feb 25, 2025

Wow, so on a whim I decided to disable IPv6 within home assistant, and everything magically worked with icloud3. What I don't understand is why, as I've had IPv6 enabled within home assistant, with it working locally on my router, for the past year with no real issues. I can even ping6 any ipv6 domain within the terminal from my home assistant device. I would ideally like to keep ipv6 enabled.

@andrew-kennedy
Copy link
Author

Update: I fully disabled IPv6 on my router, rebooted it, and reenabled it (I'm using a Unifi Dream Machine), which seems to have fixed IPv6 routing on all my devices and now IPv6 works everywhere including on the home assistant machine, and iCloud3 starts without problems. There was some kind of obscure networking issue with DHCP or something where my router itself could reach the ipv6 internet, but devices in my network couldn't. Not sure why I didn't notice the impact of this outside of iCloud3 though.

@gcobb321
Copy link
Owner

It sounds like you are making progress

@TimMeisberger
Copy link

@TimMeisberger I've gone through the log file and you have redacted a lot of things so it was hard to follow what was going on with your 3-apple accounts since you redacted them to all the same value. Also, you may have redacted 'icloud.com' which made it hard to see if there were any url problems.

In any case, when icloud3 starts it validates the username/password with a simple call to the apple authenticate url. I can see the message being sent but nothing is ever received back. Either Apple is not responding, there was an internet issue at the time when HA was being set up that cleared up later on.

Also, I can see some responses from Apple indicating the Browser is not trusted and the request to ask for a verification code is False

data.items={'hsaTrustedBrowser': False, 'hsaChallengeRequired': False}

Are using a hardware security key like a YubiKey?

I have just released v3.1.5.2b2 to handle some Apple Account issues. I do not think it will help but would like to download and install it to see if it does. It is on the iCloud3 Development Repo here.

Either download the icloud3.zip file or from HACS if you are subscribed to the iCloud3 Development site.

Thank you very much for checking the log-file and sorry for redacting all these information. I think it has something to do with my settings in my Router. I installed AdGuard when the this problem occured and did some changes in my Router-Settings. So far I was not able to find the root cause... but I will continue testing :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@kjake @andrew-kennedy @gcobb321 @TimMeisberger and others