Hyundai-Kia-Connect / hyundai_kia_connect_api

This is a Kia UVO and Hyundai Bluelink written in python. It is primary consumed by home assistant. If you are looking for a home assistant Kia / Hyundai implementation please look here: https://github.com/Hyundai-Kia-Connect/kia_uvo. Much of this base code came from reading bluelinky and contributions to the kia_uvo home assistant project.
MIT License
129 stars 73 forks source link

Not able to log in (Hyundai EU) #631

Closed Jesus-M closed 1 month ago

Jesus-M commented 1 month ago

Description

Today it stopped working. Apparently the vm.check_and_refresh_token() line gets stuck.

I have a simple script to retrieve the odometer value, refreshing if the last values was cached longer than one hour earlier, and it was working fine, until yesterday.

#!/usr/bin/python3

from datetime import datetime
from hyundai_kia_connect_api import *
from pytz import timezone

force_refresh_interval = 3600

Start = datetime.now(timezone('UTC'))
TimeFormat = "%Y-%m-%d,%H:%M:%S"

vm = VehicleManager(region=1, brand=2, username="*******@gmail.com", password="*******", pin="*****")
vm.check_and_refresh_token()
vm.update_all_vehicles_with_cached_state()

for vehicle_id in vm.vehicles.keys():
  vehicle = vm.get_vehicle(vehicle_id)
  if vehicle.last_updated_at is not None:
    if ( Start - vehicle.last_updated_at ).total_seconds() > force_refresh_interval:
#     print(f"*** Vehicle: ({vehicle.id}) / {vehicle.last_updated_at} - updating")
      vm.force_refresh_vehicle_state(vehicle_id)
      vm.update_all_vehicles_with_cached_state()

kona = vm.get_vehicle('df300a31-558c-4b25-8487-c194a2b1a715')

print(f"{Start.astimezone(timezone('Europe/Dublin')).strftime(TimeFormat)},{kona._odometer}")

What I Did

Inserting some 'prints' I saw that the script gets stuck running vm.check_and_refresh_token() , and ends few minutes later with this ouput:

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 250, in login
    authorization_code = self._get_authorization_code_with_redirect_url(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3.11/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 1481, in _get_authorization_code_with_redirect_url
    parsed_url = urlparse(response["redirectUrl"])
                          ~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'redirectUrl'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jesusm/bin/Kona-odo.py", line 18, in <module>
    vm.check_and_refresh_token()
  File "/usr/lib/python3.11/site-packages/hyundai_kia_connect_api/VehicleManager.py", line 130, in check_and_refresh_token
    self.initialize()
  File "/usr/lib/python3.11/site-packages/hyundai_kia_connect_api/VehicleManager.py", line 74, in initialize
    self.token: Token = self.api.login(self.username, self.password)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 255, in login
    authorization_code = self._get_authorization_code_with_form(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/hyundai_kia_connect_api/KiaUvoApiEU.py", line 1579, in 
_get_authorization_code_with_form
    parsed_url = urlparse(response["redirectUrl"])
                          ~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'redirectUrl'
cdnninja commented 1 month ago

On the kia_uvo GitHub repo we have lots of reports. No one can login to the native app either. Once logged out the native app stops working.

Jesus-M commented 1 month ago

I just tried with the app and it works. The script doesn't.

But if you are getting multiple reports, it might be a server issue.

Maybe a better handling of the server not responding/login issues would be helpful.

cdnninja commented 1 month ago

Open to PRs on this. I no longer own one of these cars so won't be making larger changes going forward.

Jesus-M commented 1 month ago

Open to PRs on this. I no longer own one of these cars so won't be making larger changes going forward.

I'd love to, but my developer skills are not enough for that type of changes.

Anyway, it seems to be working now, clearly nothing to do with your code, just a Bluelink issue.

Thanks!