pyicloud: 'Failed to validate the credentials from cookie'
Since yesterday I have been hitting an error when attempting to authenticate and pull calendar data.
Traceback (most recent call last):
File "chadCal.py", line 28, in <module>
api = PyiCloudService(iCloudUser, iCloudPass)
File "/Users/chadthurston/Documents/AMPScripts/pythvirtenv/lib/python2.7/site-packages/pyicloud/base.py", line 167, in __init__
self.authenticate()
File "/Users/chadthurston/Documents/AMPScripts/pythvirtenv/lib/python2.7/site-packages/pyicloud/base.py", line 190, in authenticate
raise PyiCloudFailedLoginException(msg, error)
pyicloud.exceptions.PyiCloudFailedLoginException: ('Invalid email/password combination.', PyiCloudAPIResponseError(u'Failed to validate the credentials from cookie',))
I have verified that the password is correct, and I am able to log in online. I did not find the bug reported here, however the Home Assist community has a similar issue that is being tracked, it looks like it is using pyicloud API to interact as well.
https://community.home-assistant.io/t/icloud-device-tracker-error-after-update-to-94-x/121188
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 12
- Comments: 44 (8 by maintainers)
I’ve done a little more research and it looks like there’s an additional security check at play here - something called 2SV, which is the thing that governs whether the browser client is “trusted” or not. If it’s not, then it’ll continually reenter the HSA login sequence. Basically, it’s a GET request to the endpoint https://idmsa.apple.com/appleauth/auth/2sv/trust which gives you a header back called “X-Apple-TwoSV-Trust-Token”. You then take this token alongside the standard session token and post it back to https://setup.icloud.com/setup/ws/1/accountLogin as a post body parameter called “TrustToken”.
Failure to do so results in being 2FA-challenged repeatedly. I’m seeing what I can do about that.
https://github.com/picklepete/pyicloud/pull/207 - Just opened a pull request
421 response for calls like POST https://setup.icloud.com/setup/ws/1/login? I’m trying to understand what calls are made when browser logins.
So some good testing news…
I was able to make the variable name changes in the HA icloud integration (requires_2fa to requires_2sa) and install the new pyicloud package from @PeterHedley94 github. The “standard” device_tracker component is now working well and without constant notification e-mails from Apple.
Now bear in mind - my iCloud account does not have 2SV setup - so I don’t know what impact that might have. However, for my needs it’s working again. I’m able to enumerate and track the location of my Apple devices with the iCloud Find My Phone functionality.
Hopefully the pyicloud PR will get merged with a version bump. I’ll then file a PR with HA for the icloud integration variable name changes and updates to the manifest.json.
@zeeqy I have a customized version of pyicloud supporting the Home Assistant icloud3 custom component that works with the original find-my-phone and the find-my-friends code. Additional credits for the code go to: - Original pyicloud - picklepete - https://github.com/picklepete - Update to 2fa - Peter Hadley
- https://github.com/PeterHedley94/pyicloud - Persistant Cookies - JiaJiunn Chiou - https://github.com/chumachuma/iSync - Find My Friends Update - Z Zeleznick - https://github.com/picklepete/pyicloud/pull/160
Right now is on my beta repository here but will get promoted to the custom_components/icloud3 soon.
I tried this, but still getting the following errors:
@joelmoses, @walthowd Thanks for the advice. I wonder if @picklepete is going to take that on or if it will be someone else. I think the approach I may take over the next few days is to bypass iCloud completely and just use the interface with the HA ios app to get iCloud3 going again.