question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Error during 2FA authentification

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
iPixelOldCcommented, Jul 16, 2022

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 ...

0reactions
iPixelOldCcommented, Jul 17, 2022

@mandarons Wow, so there’s a new parameter? I didn’t know that at all. But I seem to be logging in too much now and having some weird problems, obviously the password is correct but he says I’m wrong. Copy and paste too. Changed to another account also. Then I go back to the web login and the same password is logged in. It’s so weird. So I created a new container and repeated the previous operation of changing the domain name, same password but it worked.

/app # cat 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: "***"
    # Retry login interval - default is 10 minutes
    retry_login_interval: 600
  # Drive destination
  root: "icloud"
  smtp:
    # If you want to recieve email notifications about expired/missing 2FA credentials then uncomment
    # email: "sender@test.com"
    # default to is same as email above
    # to: "receiver@test.com"
    # password:
    # host: "smtp.test.com"
    # port: 587
    # If your email provider doesn't handle TLS
    # no_tls: true
  region: china # valid values are - global (default - uses .com) or china (uses .com.cn)
drive:
  destination: "drive"
  remove_obsolete: false
  sync_interval: 300
  filters:
    # File filters to be included in syncing iCloud drive content
    folders:
      - "folder1"
      - "folder2"
      - "folder3"
    file_extensions:
      # File extensions to be included
      - "pdf"
      - "png"
      - "jpg"
      - "jpeg"
photos:
  destination: "photos"
  remove_obsolete: false
  sync_inteval: 500
  filters:
    albums:
      - "album 1"
      - "album2"
    file_sizes: # valid values are original, medium and/or thumb
      - "original"
      # - "medium"
      # - "thumb"
/app # ls
CODE_OF_CONDUCT.md  README.md           icloud              run-ci.sh           venv
Dockerfile-debug    config.yaml         icloud.log          session_data
LICENSE             generate_badges.py  requirements.txt    src
/app # icloud --username=*** --session-directory=/app/session_data --region=china
Enter iCloud password for ***: 
Bad username or password for ***
Enter iCloud password for ***: 
Bad username or password for ***
Enter iCloud password for ***: 
Traceback (most recent call last):
  File "/app/venv/lib/python3.9/site-packages/icloudpy/base.py", line 336, in authenticate
    self.session.post(
  File "/app/venv/lib/python3.9/site-packages/requests/sessions.py", line 635, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
  File "/app/venv/lib/python3.9/site-packages/icloudpy/base.py", line 131, in request
    self._raise_error(response.status_code, response.reason)
  File "/app/venv/lib/python3.9/site-packages/icloudpy/base.py", line 187, in _raise_error
    raise api_error
icloudpy.exceptions.ICloudPyAPIResponseException: Not Found (404)

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

Traceback (most recent call last):
  File "/app/venv/lib/python3.9/site-packages/icloudpy/cmdline.py", line 218, in main
    ICloudPyService(
  File "/app/venv/lib/python3.9/site-packages/icloudpy/base.py", line 277, in __init__
    self.authenticate()
  File "/app/venv/lib/python3.9/site-packages/icloudpy/base.py", line 344, in authenticate
    raise ICloudPyFailedLoginException(msg, error) from error
icloudpy.exceptions.ICloudPyFailedLoginException: ('Invalid email/password combination.', ICloudPyAPIResponseException('Not Found (404)'))

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

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 303, in main
    raise RuntimeError(message) from error
RuntimeError: Bad username or password for ***
/app # ls
CODE_OF_CONDUCT.md  README.md           icloud              run-ci.sh           venv
Dockerfile-debug    config.yaml         icloud.log          session_data
LICENSE             generate_badges.py  requirements.txt    src
/app # cd venv/lib/python3.9/site-packages/icloudpy
/app/venv/lib/python3.9/site-packages/icloudpy # vi base.py #(Modified the same place)
/app/venv/lib/python3.9/site-packages/icloudpy # cd /app
/app # icloud --username=*** --session-directory=/app/session_data
Enter iCloud password for ***: 
Save password in keyring? [y/N]: y

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

/app # 

UPDATE: I changed the sync script here to return the global domain name, and I also have the same problem with the password error.

/app # vi src/sync.py # Modified to return the global domain name
/app # icloud --username=***: --session-directory=/app/session_data --region=china
Enter iCloud password for ***: 
Bad username or password for ***:
Enter iCloud password for ***: 
Bad username or password for ***
Enter iCloud password for ***: 
Traceback (most recent call last):
  File "/app/venv/lib/python3.9/site-packages/icloudpy/base.py", line 336, in authenticate
    self.session.post(
  File "/app/venv/lib/python3.9/site-packages/requests/sessions.py", line 635, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
  File "/app/venv/lib/python3.9/site-packages/icloudpy/base.py", line 131, in request
    self._raise_error(response.status_code, response.reason)
  File "/app/venv/lib/python3.9/site-packages/icloudpy/base.py", line 187, in _raise_error
    raise api_error
icloudpy.exceptions.ICloudPyAPIResponseException: Not Found (404)

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

Traceback (most recent call last):
  File "/app/venv/lib/python3.9/site-packages/icloudpy/cmdline.py", line 218, in main
    ICloudPyService(
  File "/app/venv/lib/python3.9/site-packages/icloudpy/base.py", line 277, in __init__
    self.authenticate()
  File "/app/venv/lib/python3.9/site-packages/icloudpy/base.py", line 344, in authenticate
    raise ICloudPyFailedLoginException(msg, error) from error
icloudpy.exceptions.ICloudPyFailedLoginException: ('Invalid email/password combination.', ICloudPyAPIResponseException('Not Found (404)'))

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

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 303, in main
    raise RuntimeError(message) from error
RuntimeError: Bad username or password for ***

/app # cat src/sync.py

def get_api_instance(
    username,
    password,
    cookie_directory=DEFAULT_COOKIE_DIRECTORY,
    server_region="global",
):
    return (
        ICloudPyService(
            apple_id=username,
            password=password,
            cookie_directory=cookie_directory,
            auth_endpoint="https://www.icloud.com",
            setup_endpoint="https://setup.icloud.com/setup/ws/1",
        )
        if server_region == "china"
        else ICloudPyService(
            apple_id=username,
            password=password,
            cookie_directory=cookie_directory,
        )
    )

Then I’m here in the wee hours of the morning, and I have to go to sleep. I’ll come back tomorrow to test, bye.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem Solving Login Issues with Two-Factor Authentication
This error means that when your account was set up, your login credentials were created using a username instead of using a valid...
Read more >
Fix 2FA Not Working Error In COD Warzone & MW
Want to fix the COD 2fa not working error in Warzone or Modern Warfare? In this guide we've listed a few steps to...
Read more >
My authenticator app 2FA code doesn't work ('Invalid code ...
If you have access to your 2FA codes but are receiving an 'Invalid login' message, please update the time settings on your phone...
Read more >
Common problems with two-step verification for a work or ...
If you're using two-step verification with your work or school account, it most likely means that your organization has decided you must use...
Read more >
"Incorrect Code" 2FA Troubleshooting - Poloniex Support
The most common cause for "Incorrect Code" errors is that the time on your device is not synced correctly. To make sure that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found