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

401 response when authenticating with version 1.24.0 #975

Open
scttnlsn opened this issue Oct 25, 2024 · 22 comments
Open

401 response when authenticating with version 1.24.0 #975

scttnlsn opened this issue Oct 25, 2024 · 22 comments
Labels

Comments

@scttnlsn
Copy link

Overview

401 response when authenticating with version 0.1.24

Steps to Reproduce

  1. Install version 0.1.24
  2. Run icloudpd --username '<email>' --password '<password>' --auth-only

Expected Behavior

Authentication succeeds.

Actual Behavior

Authentication fails with this error message:

pyicloud_ipd.exceptions.PyiCloudAPIResponseException: {
  "serviceErrors" : [ {
    "code" : "-20101",
    "message" : "Enter the email or phone number and password for your Apple Account.",
    "suppressDismissal" : false
  } ]
} (401)

Context

I was experiencing the authentication issues described in #970. Tried upgrading to 0.1.24 (which includes a fix for that) but I'm getting another authentication error.

@Jan108
Copy link

Jan108 commented Oct 26, 2024

I have the same problem, but I get a different error code from the API:

jan@jan:~/$ ./icloudpd-ex-1.24.0-linux-amd64 icloudpd --username '<iCloud email>' --auth-only
2024-10-26 13:46:24 DEBUG    Authenticating...
iCloud Password: 
Traceback (most recent call last):
  File "pyicloud_ipd/base.py", line 270, in authenticate
pyicloud_ipd.exceptions.PyiCloudAPIResponseException: {
  "serviceErrors" : [ {
    "code" : "-20283",
    "message" : "Enter the email or phone number and password for your Apple Account.",
    "suppressDismissal" : false
  } ]
} (401)

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

Traceback (most recent call last):
  File "starters/icloudpd_ex.py", line 122, in <module>
  File "starters/icloudpd_ex.py", line 118, in main
  File "click/core.py", line 1157, in __call__
  File "click/core.py", line 1078, in main
  File "click/core.py", line 1688, in invoke
  File "click/core.py", line 1434, in invoke
  File "click/core.py", line 783, in invoke
  File "icloudpd/base.py", line 745, in main
  File "icloudpd/base.py", line 1183, in core
  File "icloudpd/authentication.py", line 53, in authenticate_
  File "pyicloud_ipd/base.py", line 160, in __init__
  File "pyicloud_ipd/base.py", line 273, in authenticate
pyicloud_ipd.exceptions.PyiCloudFailedLoginException: ('Invalid email/password combination.', PyiCloudAPIResponseException('{\n  "serviceErrors" : [ {\n    "code" : "-20283",\n    "message" : "Enter the email or phone number and password for your Apple\xa0Account.",\n    "suppressDismissal" : false\n  } ]\n} (401)'))
[11451] Failed to execute script 'icloudpd_ex' due to unhandled exception!
version:1.24.0, commit sha:0e608f6, commit timestamp:Fri Oct 25 18:18:53 2024 CEST

@AndreyNikiforov
Copy link
Collaborator

The only ref to -20283 error code mentions app-specific password, which do not work for icloud photos. I have no clue what both of these codes mean.

General ideas to experiment with password issues:

  • remove cookies (~/.pyicloudpd by default)
  • remove pass from keyring with icloud or explicitly state --password-provider console --mfa-provider console
  • (do not use --password param to avoid char issues with the shell)

@AndreyNikiforov AndreyNikiforov changed the title 401 response when authenticating with version 0.1.24 401 response when authenticating with version 1.24.0 Oct 26, 2024
@AndreyNikiforov
Copy link
Collaborator

I checked that my account has app specific password from long ago and I am able to authenticate with regular password in 1.24.0

@Jan108
Copy link

Jan108 commented Oct 27, 2024

Cookie removal or explicitly setting the provider to console didn't help.

Setting a new password for the account solves the problem, I found the solution in this fastlane issue.

@lvdgraaff
Copy link

Cookie removal or explicitly setting the provider to console didn't help.

Setting a new password for the account solves the problem, I found the solution in this fastlane issue.

Thanks! I can confirm this solved the issue for me too.
Same as the original poster in the linked issue, I used to have a very old (>10 y) password.

@CreativePR
Copy link

We are seeing this error as well with one of our users that has a more recently set password. Using the Windows version of 1.24.0. Here is the error generated:

Traceback (most recent call last):
File "pyicloud_ipd\base.py", line 270, in authenticate
pyicloud_ipd.exceptions.PyiCloudAPIResponseException: {
"serviceErrors" : [ {
"code" : "-20101",
"message" : "Enter the email or phone number and password for your Apple Account.",
"suppressDismissal" : false
} ]
} (401)

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

Traceback (most recent call last):
File "starters\icloudpd.py", line 6, in
File "click\core.py", line 1157, in call
File "click\core.py", line 1078, in main
File "click\core.py", line 1434, in invoke
File "click\core.py", line 783, in invoke
File "icloudpd\base.py", line 745, in main
File "icloudpd\base.py", line 1183, in core
File "icloudpd\authentication.py", line 53, in authenticate_
File "pyicloud_ipd\base.py", line 160, in init
File "pyicloud_ipd\base.py", line 273, in authenticate
pyicloud_ipd.exceptions.PyiCloudFailedLoginException: ('Invalid email/password combination.', PyiCloudAPIResponseException('{\n "serviceErrors" : [ {\n "code" : "-20101",\n "message" : "Enter the email or phone number and password for your Apple\xa0Account.",\n "suppressDismissal" : false\n } ]\n} (401)'))
[16804] Failed to execute script 'icloudpd' due to unhandled exception!

@CreativePR
Copy link

We are seeing this error as well with one of our users that has a more recently set password. Using the Windows version of 1.24.0. Here is the error generated:

Traceback (most recent call last): File "pyicloud_ipd\base.py", line 270, in authenticate pyicloud_ipd.exceptions.PyiCloudAPIResponseException: { "serviceErrors" : [ { "code" : "-20101", "message" : "Enter the email or phone number and password for your Apple Account.", "suppressDismissal" : false } ] } (401)

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

Traceback (most recent call last): File "starters\icloudpd.py", line 6, in File "click\core.py", line 1157, in call File "click\core.py", line 1078, in main File "click\core.py", line 1434, in invoke File "click\core.py", line 783, in invoke File "icloudpd\base.py", line 745, in main File "icloudpd\base.py", line 1183, in core File "icloudpd\authentication.py", line 53, in authenticate_ File "pyicloud_ipd\base.py", line 160, in init File "pyicloud_ipd\base.py", line 273, in authenticate pyicloud_ipd.exceptions.PyiCloudFailedLoginException: ('Invalid email/password combination.', PyiCloudAPIResponseException('{\n "serviceErrors" : [ {\n "code" : "-20101",\n "message" : "Enter the email or phone number and password for your Apple\xa0Account.",\n "suppressDismissal" : false\n } ]\n} (401)')) [16804] Failed to execute script 'icloudpd' due to unhandled exception!

An update - had the user update their password on iCloud and tried again with the new credentials. Same problem. Here is the output:

Traceback (most recent call last):
File "pyicloud_ipd\base.py", line 270, in authenticate
pyicloud_ipd.exceptions.PyiCloudAPIResponseException: {
"serviceErrors" : [ {
"code" : "-20101",
"message" : "Enter the email or phone number and password for your Apple Account.",
"suppressDismissal" : false
} ]
} (401)

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

Traceback (most recent call last):
File "starters\icloudpd.py", line 6, in
File "click\core.py", line 1157, in call
File "click\core.py", line 1078, in main
File "click\core.py", line 1434, in invoke
File "click\core.py", line 783, in invoke
File "icloudpd\base.py", line 745, in main
File "icloudpd\base.py", line 1183, in core
File "icloudpd\authentication.py", line 53, in authenticate_
File "pyicloud_ipd\base.py", line 160, in init
File "pyicloud_ipd\base.py", line 273, in authenticate
pyicloud_ipd.exceptions.PyiCloudFailedLoginException: ('Invalid email/password combination.', PyiCloudAPIResponseException('{\n "serviceErrors" : [ {\n "code" : "-20101",\n "message" : "Enter the email or phone number and password for your Apple\xa0Account.",\n "suppressDismissal" : false\n } ]\n} (401)'))
[8548] Failed to execute script 'icloudpd' due to unhandled exception!

@Henning256
Copy link

I had the same problem even after I changed my password.
The solution was to us the --username and --password parameters.
It didn't work when us entered my username in the dialog!

@CreativePR
Copy link

With this one particular user we are using --username --password and --auth-only but each time we receive the error/output that I posted above. We had a few other users that needed to reauthenticate and they worked with no issue. It (so far) is only with this one user. Again, had this user change their password at iCloud.Com and it was checked and verifed but when using iCloudPD still this error.

@Sonnenfleck
Copy link

Sonnenfleck commented Oct 29, 2024

I had the same problem even after I changed my password. The solution was to us the --username and --password parameters. It didn't work when us entered my username in the dialog!

Wasn't enough for me. What helped was this:

icloudpd --username [email protected] --password xyz --auth-only --password-provider console --mfa-provider console

(I removed the cookies first: rm -r ~/.pyicloudpd - that alone didn't help, but I don't know if it was necessary.)

@scttnlsn
Copy link
Author

Thanks @Sonnenfleck. That also worked for me.

@CreativePR
Copy link

We tried the suggestion above using the additional items and on this one account (verified to work on iCloud.Com) still receiving an error:

Output here:
File "pyicloud_ipd\base.py", line 270, in authenticate
pyicloud_ipd.exceptions.PyiCloudAPIResponseException: {
"serviceErrors" : [ {
"code" : "-20101",
"message" : "Enter the email or phone number and password for your Apple Account.",
"suppressDismissal" : false
} ]
} (401)

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

Traceback (most recent call last):
File "starters\icloudpd.py", line 6, in
File "click\core.py", line 1157, in call
File "click\core.py", line 1078, in main
File "click\core.py", line 1434, in invoke
File "click\core.py", line 783, in invoke
File "icloudpd\base.py", line 745, in main
File "icloudpd\base.py", line 1183, in core
File "icloudpd\authentication.py", line 53, in authenticate_
File "pyicloud_ipd\base.py", line 160, in init
File "pyicloud_ipd\base.py", line 273, in authenticate
pyicloud_ipd.exceptions.PyiCloudFailedLoginException: ('Invalid email/password combination.', PyiCloudAPIResponseException('{\n "serviceErrors" : [ {\n "code" : "-20101",\n "message" : "Enter the email or phone number and password for your Apple\xa0Account.",\n "suppressDismissal" : false\n } ]\n} (401)'))
[26272] Failed to execute script 'icloudpd' due to unhandled exception!

@petebocken
Copy link

I tried deleting cookies as well, nothing works.

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/icloudpd/1.24.1/libexec/lib/python3.13/site-packages/pyicloud_ipd/base.py", line 270, in authenticate
    raise PyiCloudAPIResponseException(response.text, str(response.status_code))
pyicloud_ipd.exceptions.PyiCloudAPIResponseException: {
  "serviceErrors" : [ {
    "code" : "-20101",
    "message" : "Enter the email or phone number and password for your Apple Account.",
    "suppressDismissal" : false
  } ]
} (401)

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

Traceback (most recent call last):
  File "/opt/homebrew/bin/icloudpd", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/opt/homebrew/Cellar/icloudpd/1.24.1/libexec/lib/python3.13/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/icloudpd/1.24.1/libexec/lib/python3.13/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Cellar/icloudpd/1.24.1/libexec/lib/python3.13/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/icloudpd/1.24.1/libexec/lib/python3.13/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/icloudpd/1.24.1/libexec/lib/python3.13/site-packages/icloudpd/base.py", line 745, in main
    result = core(
        download_builder(
    ...<50 lines>...
        status_exchange,
    )
  File "/opt/homebrew/Cellar/icloudpd/1.24.1/libexec/lib/python3.13/site-packages/icloudpd/base.py", line 1183, in core
    icloud = authenticator(
    ...<8 lines>...
        status_exchange,
    )(
        username,
    ...<2 lines>...
        os.environ.get("CLIENT_ID"),
    )
  File "/opt/homebrew/Cellar/icloudpd/1.24.1/libexec/lib/python3.13/site-packages/icloudpd/authentication.py", line 53, in authenticate_
    icloud = PyiCloudService(
        filename_cleaner,
    ...<7 lines>...
        client_id=client_id,
    )
  File "/opt/homebrew/Cellar/icloudpd/1.24.1/libexec/lib/python3.13/site-packages/pyicloud_ipd/base.py", line 160, in __init__
    self.authenticate()
    ~~~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/icloudpd/1.24.1/libexec/lib/python3.13/site-packages/pyicloud_ipd/base.py", line 280, in authenticate
    raise PyiCloudFailedLoginException(msg, error) from error
pyicloud_ipd.exceptions.PyiCloudFailedLoginException: ('Invalid email/password combination.', PyiCloudAPIResponseException('{\n  "serviceErrors" : [ {\n    "code" : "-20101",\n    "message" : "Enter the email or phone number and password for your Apple\xa0Account.",\n    "suppressDismissal" : false\n  } ]\n} (401)'))

@AndreyNikiforov
Copy link
Collaborator

another project hints there is a bug in upstream SRP implementation in handling salts that started with zeros. That explains why errors appear for certain account only (salt is persisted per account) and why changing password fixes the issue (presumably salt is re-generated).

There is no explicit confirmation that bug fix worked (e.g. account with error would start working without password reset) though.

@AndreyNikiforov
Copy link
Collaborator

1.24.2 has the fix.

@AndreyNikiforov AndreyNikiforov mentioned this issue Nov 3, 2024
@petebocken
Copy link

1.24.2 has the fix.

Still not able to get it to work. Tried deleting cookies and recreating. Tried 3 different Apple accounts.

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/icloudpd/1.24.2/libexec/lib/python3.13/site-packages/pyicloud_ipd/base.py", line 270, in authenticate
    raise PyiCloudAPIResponseException(response.text, str(response.status_code))
pyicloud_ipd.exceptions.PyiCloudAPIResponseException: {
  "serviceErrors" : [ {
    "code" : "-20101",
    "message" : "Enter the email or phone number and password for your Apple Account.",
    "suppressDismissal" : false
  } ]
} (401)

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

Traceback (most recent call last):
  File "/opt/homebrew/bin/icloudpd", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/opt/homebrew/Cellar/icloudpd/1.24.2/libexec/lib/python3.13/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/icloudpd/1.24.2/libexec/lib/python3.13/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/Cellar/icloudpd/1.24.2/libexec/lib/python3.13/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/icloudpd/1.24.2/libexec/lib/python3.13/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/Cellar/icloudpd/1.24.2/libexec/lib/python3.13/site-packages/icloudpd/base.py", line 745, in main
    result = core(
        download_builder(
    ...<50 lines>...
        status_exchange,
    )
  File "/opt/homebrew/Cellar/icloudpd/1.24.2/libexec/lib/python3.13/site-packages/icloudpd/base.py", line 1183, in core
    icloud = authenticator(
    ...<8 lines>...
        status_exchange,
    )(
        username,
    ...<2 lines>...
        os.environ.get("CLIENT_ID"),
    )
  File "/opt/homebrew/Cellar/icloudpd/1.24.2/libexec/lib/python3.13/site-packages/icloudpd/authentication.py", line 53, in authenticate_
    icloud = PyiCloudService(
        filename_cleaner,
    ...<7 lines>...
        client_id=client_id,
    )
  File "/opt/homebrew/Cellar/icloudpd/1.24.2/libexec/lib/python3.13/site-packages/pyicloud_ipd/base.py", line 160, in __init__
    self.authenticate()
    ~~~~~~~~~~~~~~~~~^^
  File "/opt/homebrew/Cellar/icloudpd/1.24.2/libexec/lib/python3.13/site-packages/pyicloud_ipd/base.py", line 280, in authenticate
    raise PyiCloudFailedLoginException(msg, error) from error
pyicloud_ipd.exceptions.PyiCloudFailedLoginException: ('Invalid email/password combination.', PyiCloudAPIResponseException('{\n  "serviceErrors" : [ {\n    "code" : "-20101",\n    "message" : "Enter the email or phone number and password for your Apple\xa0Account.",\n    "suppressDismissal" : false\n  } ]\n} (401)'))

@AndreyNikiforov
Copy link
Collaborator

I tried deleting cookies as well, nothing works.

A number of thoughts on the subject:

  • besides cookies, ppl are clearing keyring passwords as well; I think alternatively you can specify --password-provider console --mfa-provider console to exclude keyring checks; I do not understand how keyring may be related, but worth trying
  • it may be more accurate to troubleshoot using icloudpd binary instead of homebrew install
  • if you proceed with homebrew version, check srp version used
  • error that you see may be not related to the salt issue at all, then no path forward I can think of
  • last option is to change icloud password - ppl reported that it helped

@petebocken
Copy link

* last option is to change icloud password - ppl reported that it helped

This worked! Thanks.

Also, for whatever reason I'm again able to remove the --password from my script and rely completely on the saved keyring.

@AndreyNikiforov
Copy link
Collaborator

We tried the suggestion above using the additional items and on this one account (verified to work on iCloud.Com) still receiving an error:

Output here: File "pyicloud_ipd\base.py", line 270, in authenticate pyicloud_ipd.exceptions.PyiCloudAPIResponseException: { "serviceErrors" : [ { "code" : "-20101", "message" : "Enter the email or phone number and password for your Apple Account.", "suppressDismissal" : false } ] } (401)

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

Traceback (most recent call last): File "starters\icloudpd.py", line 6, in File "click\core.py", line 1157, in call File "click\core.py", line 1078, in main File "click\core.py", line 1434, in invoke File "click\core.py", line 783, in invoke File "icloudpd\base.py", line 745, in main File "icloudpd\base.py", line 1183, in core File "icloudpd\authentication.py", line 53, in authenticate_ File "pyicloud_ipd\base.py", line 160, in init File "pyicloud_ipd\base.py", line 273, in authenticate pyicloud_ipd.exceptions.PyiCloudFailedLoginException: ('Invalid email/password combination.', PyiCloudAPIResponseException('{\n "serviceErrors" : [ {\n "code" : "-20101",\n "message" : "Enter the email or phone number and password for your Apple\xa0Account.",\n "suppressDismissal" : false\n } ]\n} (401)')) [26272] Failed to execute script 'icloudpd' due to unhandled exception!

@CreativePR try latest (1.24.3 as of writing), clearing cookies. If still see the same error, post: a) cmd line using downloaded binary b) output (as you were doing before)

@CreativePR
Copy link

We tried the suggestion above using the additional items and on this one account (verified to work on iCloud.Com) still receiving an error:
Output here: File "pyicloud_ipd\base.py", line 270, in authenticate pyicloud_ipd.exceptions.PyiCloudAPIResponseException: { "serviceErrors" : [ { "code" : "-20101", "message" : "Enter the email or phone number and password for your Apple Account.", "suppressDismissal" : false } ] } (401)
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "starters\icloudpd.py", line 6, in File "click\core.py", line 1157, in call File "click\core.py", line 1078, in main File "click\core.py", line 1434, in invoke File "click\core.py", line 783, in invoke File "icloudpd\base.py", line 745, in main File "icloudpd\base.py", line 1183, in core File "icloudpd\authentication.py", line 53, in authenticate_ File "pyicloud_ipd\base.py", line 160, in init File "pyicloud_ipd\base.py", line 273, in authenticate pyicloud_ipd.exceptions.PyiCloudFailedLoginException: ('Invalid email/password combination.', PyiCloudAPIResponseException('{\n "serviceErrors" : [ {\n "code" : "-20101",\n "message" : "Enter the email or phone number and password for your Apple\xa0Account.",\n "suppressDismissal" : false\n } ]\n} (401)')) [26272] Failed to execute script 'icloudpd' due to unhandled exception!

@CreativePR try latest (1.24.3 as of writing), clearing cookies. If still see the same error, post: a) cmd line using downloaded binary b) output (as you were doing before)

Downloaded the 1.24.3 release for Windows and this was the error output on that same account:

2024-11-03 21:20:04 DEBUG Authenticating...
Traceback (most recent call last):
File "pyicloud_ipd\base.py", line 270, in authenticate
pyicloud_ipd.exceptions.PyiCloudAPIResponseException: {
"serviceErrors" : [ {
"code" : "-20101",
"message" : "Enter the email or phone number and password for your Apple Account.",
"suppressDismissal" : false
} ]
} (401)

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

Traceback (most recent call last):
File "starters\icloudpd.py", line 6, in
File "click\core.py", line 1157, in call
File "click\core.py", line 1078, in main
File "click\core.py", line 1434, in invoke
File "click\core.py", line 783, in invoke
File "icloudpd\base.py", line 745, in main
File "icloudpd\base.py", line 1183, in core
File "icloudpd\authentication.py", line 53, in authenticate_
File "pyicloud_ipd\base.py", line 160, in init
File "pyicloud_ipd\base.py", line 280, in authenticate
pyicloud_ipd.exceptions.PyiCloudFailedLoginException: ('Invalid email/password combination.', PyiCloudAPIResponseException('{\n "serviceErrors" : [ {\n "code" : "-20101",\n "message" : "Enter the email or phone number and password for your Apple\xa0Account.",\n "suppressDismissal" : false\n } ]\n} (401)'))
[4292] Failed to execute script 'icloudpd' due to unhandled exception!

Other accounts are not having a problem reauthenticating (as before) - it is only this one account. Verified that the account can be logged in with the same exact credentials on icloud.com

@AlexSmirnov9107
Copy link

same here

@iowk
Copy link
Contributor

iowk commented Nov 7, 2024

Starting from an hour ago, requests to signin/init are giving 503 responses.

Is anyone facing similar issue?

Update: It's working again now. It was failing on multiple accounts that worked before even with different PCs. Weird.

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

No branches or pull requests

10 participants