gcobb321 / icloud3

iCloud3 v3 - iCloud3 is an advanced iDevice tracker that uses Apple iCloud account and HA Companion App data for presence detection and location based automations.
MIT License
546 stars 54 forks source link

Fail to login (China URL Access) #280

Closed lenhoo closed 11 months ago

lenhoo commented 1 year ago

Try to login from the icloud3 v3 integration, I input my username and password correctly, and tried several times, but here is the error

ERROR (MainThread) [icloud3-cf] Error logging into iCloud service: Login Error (Invalid username/password)/571

gcobb321 commented 1 year ago

That means there was a problem logging into your iCloud account.

  1. Turn on Log Level Debug to capture some error logging. Configure Settings > Page 2 > Format Parameters screen, set Log Level = Debug-Auto Reset
  2. Restart HA
  3. Enter the Apple ID/password again. Configure Settings > iCloud Account & iOS App Data Sources screen

If you still get the error,

  1. Clear the web interface session cookie files. Request a new Apple ID Verification Code. Configure Settings > Enter/Request Verification Code screen m. Keep track of the code you may get.
  2. Enter the Apple ID/password again. Configure Settings > iCloud Account & iOS App Data Sources screen again.

If it still fails, email the config/icloud3-0.log file to geekstergary@gmail.com and I’ll look at the detail errors received from Apple during the login process

lenhoo commented 1 year ago

I followed your solution step by step still no luck, logfile was sent to your email, thank you

lenhoo commented 1 year ago

I find it set my region in US instead of China in icloud3-0.log. So I modified HOME_ENDPOINT and SETUP_ENDPOINT in pyicloud_ic3.py to .com.cn, it's finally working. Why it assigned wrong country code, can it be fixed?

gcobb321 commented 1 year ago

I fixed the way that was handled in version pr1.4.

The country code is from HA and it was upper case (CN). I was handling it like it was lower case (cn) incorrectly.

In pr1.4,. I also added a parameter in the config/.storage/icloud3/configuration file (icloud_server_endpoint_suffix) that can be set if the HA country code it’s wrong or does not work. I will be adding a field to Configure Settings > Page 2 > Tracking Parameters screen or an another screen to set this field. If pr1.4 does not work automatically, edit it so it reads _icloud_server_endpointsuffix: “cn” after you install pr1.4, which will erase the code changes to pyicloud_ic3.py

lenhoo commented 1 year ago

Thank you, cant't wait to test it

lenhoo commented 1 year ago

Updated to pr1.4. Do not find country code option in 'Configure Settings > Page 2 > Tracking Parameters'. But change to icloud_server_endpoint_suffix: “cn” is working, thank you.

gcobb321 commented 1 year ago

I had added that sometime to 'Configure Settings > Page 2 > Tracking Parameters' when I was away on vacation several weeks ago but think the code was overwritten and lost. I'll add it for the next update.

It should pick up the HA Country Code field (CN) when it starts and create the .cn endpoint suffix without you having to do anything. For that to be used, the config parameter should be empty (_icloud_server_endpointsuffix: “”). Can you set it to empty and restart HA to see if that works and let me know? If not, you can set it back to 'cn' so you will be tracking agsin.

Thanks

gcobb321 commented 1 year ago

I was cleaning out some email and saw the log file you sent a few days ago. I noticed that the HA Country Code is JP, not CN like I thought it would be. In that case, the HA Country Code field would not generate the '.cn' suffix and you would need to override it using the (icloud_server_endpoint_suffix: “cn”) parameter like you did before. So there is no need to do the text in my previous message.

FYI-The HA Location Info is: {'country_code': 'JP', 'region_code': '13', 'zip_code': '151-0053', 'region_name': 'Tokyo', 'city': 'Tokyo', 'time_zone': 'Asia/Tokyo', 'latitude': 35.6893, 'longitude': 139.6899, 'use_metric': True}

gcobb321 commented 1 year ago

I just posted a new release (pr1.5) in the iCloud3 v3 Development Repository here that adds an item to the iCloud Account & iOS App screen to enable the '.cn' URL suffix for China.

Go there, click Assets, select icloud3.zip to download it, unzip it in the icloud3 directory and restart HA.

Then go to the Configure Settings > iCloud Account & iOS App screen to see if it is enabled (it should be). The way it will work is to look at the HA Country Code when starting for the first time. If it is 'CN', the 'cn' code is set in the configuration file and the items should be enabled.

lenhoo commented 11 months ago

It automaticly added 'cn' to the suffix after I enabled the option in pr1.5. Hurray!