icloud-photos-downloader / icloud_photos_downloader

A command-line tool to download photos from iCloud
MIT License
6.57k stars 534 forks source link

[MacOS] Unknown reason authentication error #700

Closed Brett-StrayThought closed 8 months ago

Brett-StrayThought commented 11 months ago

Overview

I previously used icloudpd without issue. I copied/pasted the command I used last time (don't know which version) that worked but it doesn't work this time in 1.16.2. It fails trying to login with 2FA. I tried many times, and manually logged into iCloud to be sure username and password are indeed correct.

Note in the error it says "Failed to send two-factor authentication code" however I received the SMS and also every one of my Apple devices prompted me asking to Allow/Deny too.

Steps to Reproduce

  1. Run "icloudpd --directory /Users/brett/Downloads/iPhoneImport/Brett --username @icloud.com --password --recent 1340 --set-exif-datetime --folder-structure {:%Y/%m}"
  2. Results in error:
    
    MBP iPhone Import$ icloudpd --directory /Users/brett/Downloads/iPhoneImport/Brett --username <my username>@icloud.com --password <my password> --recent 1340 --set-exif-datetime --folder-structure {:%Y/%m}
    2023-10-03 10:31:22 DEBUG    Authenticating...
    2023-10-03 10:31:23 INFO     Two-step/two-factor authentication is required
    0: SMS to ********10
    1: Enter two-factor authentication code
    Please choose an option: [0]: Usage: icloudpd <options>
    Try 'icloudpd -h' for help.

Error: No such option: -B

2023-10-03 10:31:59 ERROR Failed to send two-factor authentication code multiprocessing/resource_tracker.py:104: UserWarning: resource_tracker: process died unexpectedly, relaunching. Some resources might leak. MBP iPhone Import$ Usage: icloudpd Try 'icloudpd -h' for help.

Error: No such option: -B

MBP iPhone Import$


## Expected Behavior
Expected it would work, or give a better reason for failure. Especially unsure what the "Error: No such option: -B" that pops up means.

## Actual Behavior
Didn't work

## Context
boredazfcuk commented 11 months ago

Does your password have a -B in it by any chance?

Brett-StrayThought commented 11 months ago

Good question! But it does not. It doesn't contain anything other than letters/numbers. Same for username.

Brett-StrayThought commented 11 months ago

I did some Googling, and the "Error: No such option: -B" is odd and I could only find one other person who mentioned it.

https://www.mactechnews.de/journals/entry/iCloud-Mediathek-exportieren-und-Originale-sichern-1046.html

MrChad0815 commented 11 months ago

To the best of my knowledge, the ever-repeating misleading message

 Usage: icloudpd Try 'icloudpd -h' for help.
Error: No such option: -B

appears on Apple Silicon machines (only?) and has no other negative effects

It is somehow caused by the interaction of the Python runtime system (multiprocessing libraries) and Apple's Rosetta machine code translation. The Python runtime system seems to believe the program has crashed and tries to restart it with some strange arguments "-B" and a few others others.

Brett-StrayThought commented 11 months ago

Interesting. I'm on an Intel MacBook Pro so I don't think in this case it could be that.

AndreyNikiforov commented 11 months ago

Last time I saw option -B mentioned was in the context of ADP in #687 . In general, ADP & icloudpd do not work together.

MrChad0815 commented 11 months ago

not related to ADP - as it is not in use here .--------------------------------- you can work around the issue in your main() like this:

def main(): try:

when this is called from within an app-bundle

    # the multiprocessing.resource_tracker kicks in after every download
    # and tries to start a second instance with several (unknown) arguments
    # possibly due to a leak of some sort
    # this code will detect the arguments and terminate the secondary instance when it starts
    for a in sys.argv:
        if 'multiprocessing.resource_tracker' in a:
            sys.exit(1)
finally:
    pass

.# followed by your code

.------------------------------------ The second instance will receive a series of arguments including a string ... multiprocessing.resource_tracker ... originating from: https://github.com/python/cpython/blob/main/Lib/multiprocessing/resource_tracker.py (see line 131)

Brett-StrayThought commented 11 months ago

I went back to the original repo for pyicloud and found it works fine with no errors or the strange "not option -B" error. So before moving on, summary is:

alixmartineau commented 11 months ago

I have had the same problem for a while (icloudpd, version 1.14.5 on Apple M2 Pro, Python 3.11.5)

$ icloudpd --directory 'Photos' --username 'xxx@xxx.xxx' --auto-delete
2023-10-04 12:57:08 DEBUG    Authenticating...
iCloud Password: 
2023-10-04 12:57:18 DEBUG    Looking up all photos and videos from album All Photos...
2023-10-04 12:57:18 INFO     Downloading 5002 original photos and videos to Photos ...
  0%|                                                                                                  | 0/5002 [00:00<?, ?it/s]Usage: icloudpd <options>
Try 'icloudpd -h' for help.

Error: No such option: -B
Photos/2014/12/24/IMG_0062.JPG already exists.: 100%|#######################################| 5002/5002 [05:22<00:00, 15.53it/s]2023-10-04 13:02:41 INFO     All photos have been downloaded!
2023-10-04 13:02:41 INFO     Deleting any files found in 'Recently Deleted'...
multiprocessing/resource_tracker.py:104: UserWarning: resource_tracker: process died unexpectedly, relaunching.  Some resources might leak.

Usage: icloudpd <options>
Try 'icloudpd -h' for help.

Error: No such option: -B

I should clarify that icloudpd still works, the pictures are downloaded as expected, but the output is all mangled and unreadable.

Happens both with zsh and bash.

I also tried : different --log-levels, passing password as an argument, --no-progress-bar but these errors still get printed to stdout.

AndreyNikiforov commented 11 months ago

Resource leak was noticed on mac before (#668), although symptoms were different.

alixmartineau commented 11 months ago

Thanks @AndreyNikiforov, just tested icloudpd==1.14.2 and the problem is not present.

flappah commented 10 months ago

I think it has to do with the existence of security keys in the apple-id. I had a similar error and after removing both security keys from my apple-id icloudpd worked again.

itwasabhi commented 9 months ago

+1 with this issue (icloudpd, version 1.16.2), Apple M2

juju4 commented 9 months ago

I think it has to do with the existence of security keys in the apple-id. I had a similar error and after removing both security keys from my apple-id icloudpd worked again.

Any plan to support security keys (FIDO2/webauthn)? It seems that when configured, OTP is not available anymore. Also security keys configuration remove existing MFA sessions. Tested with icloudpd 1.16.2. Need to remove them to use OTP again.

https://support.apple.com/en-ca/guide/iphone/iph5acc5b28c/ios "Note: If you remove all security keys from a device, the device reverts to using six-digit verification codes for two-factor authentication."

gaffneyd4 commented 9 months ago

If this error is caused by FIDO security keys being enabled as the 2FA method on the icloud account, then we can close this issue in favor of #583

alixmartineau commented 9 months ago

It’s not linked. I have never had FIDO 2FA enabled on my account. 

tooluser commented 8 months ago

I have the same issue on my Intel Mac mini, v 1.16.2, no FIDO security key.

AndreyNikiforov commented 8 months ago

I have the same issue on my Intel Mac mini, v 1.16.2, no FIDO security key.

Upgrade to 1.17.1. Versions prior to 1.17.0 stoped working recently due to changes in Apple API, See #729