python-caldav / caldav

Apache License 2.0
321 stars 95 forks source link

CalDAV iCloud Sign-in Error on Home Assistant: Path Handling Problem #393

Closed gtmax500 closed 5 months ago

gtmax500 commented 5 months ago

Hello,

I have had the CalDAV integration in Home Assistant working with my iCloud calendars for a few weeks now but about a week ago I started getting sync errors. I deleted the integration and tried to log in again but it keeps failing with an “unknown error occurred”.

I did find this error in the logs which asked me to raise an issue here though I could not find the traceback:

Logger: caldav Source: /usr/local/lib/python3.12/site-packages/caldav/objects.py:303 First occurred: April 13, 2024 at 08:59:55 (6 occurrences) Last logged: 21:27:54

Possibly the server has a path handling problem, possibly the URL configured is wrong. Path expected: /.well-known/caldav, path found: ['/8034509913/principal/'] Please raise an issue at https://github.com/python-caldav/caldav/issues or reach out to t-caldav@tobixen.no, include this error and the traceback and tell what server you are using. Continuing, probably everything will be fine

I am not sure this is the cause of my login issue but it may be a part of it. I am also not sure which version of python-Caldav I am running but here is a link to the source code .

My login settings to connect to my iCloud calendar are:

Calendar URL: https://caldav.icloud.com/.well-known/caldav Username: iCloud username Password: iCloud App Specific Password (Format: xxxx-xxxx-xxxx-xxxx)

Again, it was working for a little while using those settings but now I can’t login.

tobixen commented 5 months ago

Try to use only https://caldav.icloud.com/ as the URL - though, the warning above indicates that things are working anyway.

If things have stopped working, then something must have changed. If you haven't changed the configuration or upgraded HomeAssistant, then it's likely that the change is at the server side. I've found that there is absolutely no official information stating that iCloud supports the CalDAV protocol - so Apple is free to cripple the service or shut it down completely - though I expect that it will be quite clear both in the issue tracker on HomeAssistant, the python-caldav library and other places if this is a general problem affecting all iCloud users. Could it be that the app-specific password has a lifetime and has expired?

gtmax500 commented 5 months ago

Turns out it was because I had IPV6 enabled in HomeAssistant. After disabling IPV6, I was able to log in to my iCloud account through the HomeAssistant CalDAV integration in an instant. I am not sure how IPV6 suddenly got enabled but thank you for the prompt assistance in any case.

tobixen commented 5 months ago

I'm more wondering why this error would occur with IPv6 in the first place. The common pitfall with dual-stack implementations (systems set up with both IPv4 and IPv6) is that firewalls are configured differently or that some DNS pointers are wrongly set up, causing timeout issues or connection issues, not "unknown error" after doing some parts of the handshake. Well, the iCloud caldav implementation has some kind of sharding going on, you start with caldav.icloud.com, and then one gets redirected to something like caldav-p642.icloud.com if I remember correct - could be that the AAAA-record for caldav.icloud.com is correct while AAAA for caldav-p642.icloud.com is incorrect.

In any case, happy that the problem got solved, and if anyone else has problems with iCloud, I will try to remember to ask them to check if they are on IPv4 or IPv6 :-)