icloudpy icon indicating copy to clipboard operation
icloudpy copied to clipboard

icloudpy.exceptions.ICloudPyFailedLoginException: ('Invalid authentication token.', ICloudPyAPIResponseException('Missing apple_id field'))

Open runfengXie opened this issue 1 year ago • 7 comments

I got the following exception when I ran it

Traceback (most recent call last):
  File "C:\Work\Env\python\Lib\site-packages\icloudpy\base.py", line 364, in _authenticate_with_token
    req = self.session.post(
  File "C:\Work\Env\python\Lib\site-packages\requests\sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
  File "C:\Work\Env\python\Lib\site-packages\icloudpy\base.py", line 158, in request
    self._raise_error(code, reason)
  File "C:\Work\Env\python\Lib\site-packages\icloudpy\base.py", line 187, in _raise_error
    raise api_error
icloudpy.exceptions.ICloudPyAPIResponseException: Missing apple_id field

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Work\pythonProjects\demo\pythonProject\find-my-phone-demo-02.py", line 4, in <module>
    api = ICloudPyService('*****', '******', home_endpoint="https://www.icloud.com.cn",setup_endpoint="https://setup.icloud.com.cn/setup/ws/1",)
  File "C:\Work\Env\python\Lib\site-packages\icloudpy\base.py", line 279, in __init__
    self.authenticate()
  File "C:\Work\Env\python\Lib\site-packages\icloudpy\base.py", line 348, in authenticate
    self._authenticate_with_token()
  File "C:\Work\Env\python\Lib\site-packages\icloudpy\base.py", line 370, in _authenticate_with_token
    raise ICloudPyFailedLoginException(msg, error) from error
icloudpy.exceptions.ICloudPyFailedLoginException: ('Invalid authentication token.', ICloudPyAPIResponseException('Missing apple_id field'))

How can I test it to make it work?

Here is my run test code

from icloudpy import ICloudPyService
# api = ICloudPyService('[email protected]', 'password')
# For China region
api = ICloudPyService('13925629668', 'xrf64668', home_endpoint="https://www.icloud.com.cn",setup_endpoint="https://setup.icloud.com.cn/setup/ws/1",)

if __name__ == '__main__':
    print(api)

runfengXie avatar Aug 09 '24 06:08 runfengXie

Try providingcookie_directory parameter pointing to some local directory path. Also, double check username and password. Username should be your icloud email address and password should be icloud.com password (and not application password).

mandarons avatar Aug 22 '24 15:08 mandarons

尝试提供cookie_directory指向某个本地目录路径的参数。另外,请仔细检查用户名和密码。用户名应该是您的 icloud 电子邮件地址,密码应该是 icloud.com 密码(而不是应用程序密码)。

Encountered the same problem, and this happened again for accounts without 2FA authentication.

14278358 avatar Sep 24 '24 07:09 14278358

Do you have 2FA enabled? If not, try enabling it and see if that resolves the problem.

mandarons avatar Nov 27 '24 17:11 mandarons

@mandarons i meet the same problem. Regin china wrong,but if i change to us account,it's right.

roiding avatar Oct 31 '25 05:10 roiding

Thanks, I'll test it again.

runfengXie avatar Nov 03 '25 08:11 runfengXie

Thanks, I'll test it again.

i said that i meet the same problem.have you solved the problem?how to do. it seems something modified since last year between china region and oversea

roiding avatar Nov 03 '25 09:11 roiding

It has no effect.

runfengXie avatar Nov 03 '25 11:11 runfengXie