icloud-drive-docker: [BUG] Error during 2FA authentification

Describe the bug After execting the login command given in README.md

docker exec -it icloud /bin/sh -c "icloud --username=xxxx --session-directory=/app/session_data"

The following error shows:

tian@dorm-synology:/volume1/docker/icloud-drive$ sudo docker exec -it icloud /bin/sh -c "icloud --username=testtest@testtest.com --session-directory=/app/session_data"
Enter iCloud password for testest@testtest.com:
Traceback (most recent call last):
  File "/app/venv/bin//icloud", line 8, in <module>
    sys.exit(main())
  File "/app/venv/lib/python3.9/site-packages/icloudpy/cmdline.py", line 207, in main
    api = ICloudPyService(
  File "/app/venv/lib/python3.9/site-packages/icloudpy/base.py", line 273, in __init__
    self.authenticate()
  File "/app/venv/lib/python3.9/site-packages/icloudpy/base.py", line 344, in authenticate
    self._webservices = self.data["webservices"]
KeyError: 'webservices'

To Reproduce Steps to reproduce the behavior:

  1. Execute the command above.
  2. See error

Configuration If applicable, please share the configuration details

docker-compose.yaml:

version: "3.4"
services:
  icloud:
    image: mandarons/icloud-drive
    environment:
      - PUID=1026
      - GUID=100
    env_file:
      - /volume1/docker/icloud-drive/.env.icloud
    container_name: icloud
    restart: unless-stopped
    volumes:
      - /volume1/docker/icloud-drive/config.yaml:/app/config.yaml
      - /volume2/Onedrive/icloud:/app/icloud/drive
      - /volume1/docker/icloud-drive/session_data:/app/session_data

config.yaml:

app:
  logger:
    # level - debug, info (default), warning or error
    level: "info"
    # log filename icloud.log (default)
    filename: "icloud.log"
  credentials:
    # iCloud drive username
    username: "testest@testtest.com"
    # Retry login interval - default is 10 minutes
    retry_login_interval: 600
  # Drive destination
  root: "icloud"
  smtp:
    ...
drive:
  destination: "drive"
  remove_obsolete: false
  sync_interval: 300

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

It seems to work, but it still needs to be modified in one place, otherwise it will report the same webservices error.

sed -i -e "s#icloud.com/#icloud.com.cn/#" -e "s#icloud.com'#icloud.com.cn'#" "$(pip show icloudpy | grep "Location" | awk '{print $2}')/icloudpy/base.py"
cd /app/venv/lib/python3.9/site-packages/icloudpy
vi base.py

then modify HOME_ENDPOINT (I don’t know why it hasn’t been modified by sed command)

class ICloudPyService(object):                                                   
    """                                                                          
    A base authentication class for the iCloud service. Handles the              
    authentication required to access iCloud services.                           
                                                                                 
    Usage:                                                                       
        from src import ICloudPyService                                          
        icloudpy = ICloudPyService('username@apple.com', 'password')             
        icloudpy.iphone.location()                                               
    """                                                                          
                                                                                 
    AUTH_ENDPOINT = "https://idmsa.apple.com/appleauth/auth"                     
    HOME_ENDPOINT = "https://www.icloud.com"                                  
    SETUP_ENDPOINT = "https://setup.icloud.com.cn/setup/ws/1"

to

class ICloudPyService(object):                                                   
    """                                                                          
    A base authentication class for the iCloud service. Handles the              
    authentication required to access iCloud services.                           
                                                                                 
    Usage:                                                                       
        from src import ICloudPyService                                          
        icloudpy = ICloudPyService('username@apple.com', 'password')             
        icloudpy.iphone.location()                                               
    """                                                                          
                                                                                 
    AUTH_ENDPOINT = "https://idmsa.apple.com/appleauth/auth"                     
    HOME_ENDPOINT = "https://www.icloud.com.cn"                                  
    SETUP_ENDPOINT = "https://setup.icloud.com.cn/setup/ws/1"

It’s work. Photos are also starting to download。

/app # icloud --username=xxx --session-directory=/app/session_data
Bad username or password for xxx
Enter iCloud password for xxx: 
Save password in keyring? [y/N]: y

Two-step authentication required. 
Please enter validation code
(string) --> 000000

/app 
2022-07-16 12:09:45,044 :: INFO :: root :: sync_photos.py :: 37 :: Downloading /app/icloud/photos/哔哩哔哩/IMG_4634.JPG ...

2022-07-16 12:09:48,792 :: INFO :: root :: sync_photos.py :: 37 :: Downloading /app/icloud/photos/哔哩哔哩/IMG_4633.JPG ...

2022-07-16 12:09:53,130 :: INFO :: root :: sync_photos.py :: 37 :: Downloading /app/icloud/photos/哔哩哔哩/IMG_4632.JPG ...

2022-07-16 12:09:56,400 :: INFO :: root :: sync_photos.py :: 37 :: Downloading /app/icloud/photos/哔哩哔哩/IMG_4631.JPG ...

2022-07-16 12:09:57,214 :: INFO :: root :: sync_photos.py :: 37 :: Downloading /app/icloud/photos/哔哩哔哩/IMG_4630.JPG ...

2022-07-16 12:09:57,660 :: INFO :: root :: sync_photos.py :: 37 :: Downloading /app/icloud/photos/哔哩哔哩/IMG_4629.JPG ...

2022-07-16 12:09:58,576 :: INFO :: root :: sync_photos.py :: 37 :: Downloading /app/icloud/photos/哔哩哔哩/IMG_4628.JPG ...

2022-07-16 12:09:59,231 :: INFO :: root :: sync_photos.py :: 37 :: Downloading /app/icloud/photos/哔哩哔哩/IMG_4627.JPG ...

2022-07-16 12:09:59,625 :: INFO :: root :: sync_photos.py :: 37 :: Downloading /app/icloud/photos/哔哩哔哩/IMG_4626.JPG ...