DurgNomis-drol / mytoyota

Python client for Toyota Connected Services API
MIT License
77 stars 32 forks source link

running simple_client_example.py => E-Mail with verification code from toyota #277

Closed lhumb closed 10 months ago

lhumb commented 10 months ago

Describe the bug When running simple_client_example.py I get an Authentication Error plus an e-mail from toyota with a verification code.

`Deine Anmeldung in der MyToyota App ist fast fertig, du musst nur noch deine E-Mail-Adresse bestätigen. Bitte gebe den Verifizeriungscode ein, wenn du dazu aufgefordert wirst.

Dies ist der sechsstellige Verifizierungscode: 080628 Dieser Code ist fünf Minuten lang gültig`

Where should I place/save this code?

To Reproduce Steps to reproduce the behavior:

homeassistant@aberddi:~/.homeassistant/custom_components/mytoyota$ python simple_client_example.py 

Logging in...

Traceback (most recent call last):
  File "mytoyota/simple_client_example.py", line 83, in <module>
    loop.run_until_complete(get_information())
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^

  File "mytoyota/simple_client_example.py", line 43, in get_information
    await client.login()

  File "mytoyota/client.py", line 58, in login
    await self._api.controller.login()

  File "mytoyota/controller.py", line 62, in login
    await self._update_token()

  File "mytoyota/controller.py", line 74, in _update_token
    await self._authenticate()

  File "mytoyota/controller.py", line 105, in _authenticate
    raise ToyotaLoginError("Authentication Failed. Unknown method.")
mytoyota.exceptions.ToyotaLoginError: Authentication Failed. Unknown method.

Expected behavior After saving the verification-code at ?? simple_client_example.py should run ;-)

CM000n commented 10 months ago

Hi @lhumb , thx for reporting. Have you already set up your car via the MyToyota app? The mytoyota Python package only works if your car was previously set up via the official app.

lhumb commented 10 months ago

Hi Simon @CM000n – I use the mentioned App to get data for my car and at first I though I should open it, to activate the api via verification code, but nothing happened … but I have'nt set up multimedia elements in the app. … perhaps I should?

CM000n commented 10 months ago

Sry don't know what you mean with multimedia elements.

If you can already see data such as remaining range, mileage etc. in the app, this is set up and mytoyota should also work. If not, your vehicle either does not support the connected services or they have not yet been set up correctly.

It is also possible, if there is a separate registration process for your multimedia unit in the App, that the API ist reporting this as some kind of separate "vehicle". The fact that mytoyota is iterating over all vehicles may trigger the registration process for them. Unfortunately, I do not have a vehicle with a corresponding multimedia unit myself and therefore cannot reproduce this behavior.

lhumb commented 10 months ago

TNX -- I will try.

CM000n commented 10 months ago

All right, please let us know if it worked 😊

By the way, since I'm just looking at your error output again. The mytoyota Lib is not intended to be used directly as a custom_component in Home Assistant. 😉

lhumb commented 10 months ago

ok … but I deleted the complete path data, to be sure for anonymizing. In the meantime I looked at the personal privacy website at https://www.toyota.de/customer/portal#/myDetails there I decided that toyota has no access any data, but »Einblick und Analysen« … perhaps this makes a difference and so I'm not able to get a verified access?

CM000n commented 10 months ago

What do you mean with path data and where and how did you deleted it? Can you share a Screenshot from your App?

lhumb commented 10 months ago

a) I shortened the pathes in the error message b) see attached file 2024-01-07T17:40_sc_myt

CM000n commented 10 months ago

a) I shortened the pathes in the error message b) see attached file ...

This looks like you are still using the old MyT App and not the current MyToyota App :wink: This means that your vehicle has probably not yet been migrated to the current API which is required for mytoyota >= 1.0.

lhumb commented 10 months ago

Oh … thank you very much … indeed … now with the current MyToyota App the error is different:

(homeassistant) homeassistant@aberddi:/home/humbert/dokumente/photovoltaik-wallbox/mytoyota$ python simple_client_example.py 
Logging in...
Retrieving cars...
Traceback (most recent call last):
  File "/oldroot/home/humbert/dokumente/photovoltaik-wallbox/mytoyota/simple_client_example.py", line 83, in <module>
    loop.run_until_complete(get_information())
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/oldroot/home/humbert/dokumente/photovoltaik-wallbox/mytoyota/simple_client_example.py", line 49, in get_information
    await car.update()
  File "/oldroot/home/humbert/dokumente/photovoltaik-wallbox/mytoyota/mytoyota/models/vehicle.py", line 113, in update
    for name, data in await responses:
                      ^^^^^^^^^^^^^^^
  File "/oldroot/home/humbert/dokumente/photovoltaik-wallbox/mytoyota/mytoyota/models/vehicle.py", line 107, in parallel_wrapper
    r = await function()
        ^^^^^^^^^^^^^^^^
  File "/oldroot/home/humbert/dokumente/photovoltaik-wallbox/mytoyota/mytoyota/api.py", line 135, in get_vehicle_electric_status_endpoint
    return await self._request_and_parse(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/oldroot/home/humbert/dokumente/photovoltaik-wallbox/mytoyota/mytoyota/api.py", line 49, in _request_and_parse
    return model(**response)
           ^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 2 validation errors for ElectricResponseModel
payload -> fuelLevel
  field required (type=value_error.missing)
payload -> fuelRange
  field required (type=value_error.missing)
CM000n commented 10 months ago

Oh … thank you very much … indeed … now with the current MyToyota App the error is different:

(homeassistant) homeassistant@aberddi:/home/humbert/dokumente/photovoltaik-wallbox/mytoyota$ python simple_client_example.py 
Logging in...
Retrieving cars...
Traceback (most recent call last):
  File "/oldroot/home/humbert/dokumente/photovoltaik-wallbox/mytoyota/simple_client_example.py", line 83, in <module>
    loop.run_until_complete(get_information())
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/oldroot/home/humbert/dokumente/photovoltaik-wallbox/mytoyota/simple_client_example.py", line 49, in get_information
    await car.update()
  File "/oldroot/home/humbert/dokumente/photovoltaik-wallbox/mytoyota/mytoyota/models/vehicle.py", line 113, in update
    for name, data in await responses:
                      ^^^^^^^^^^^^^^^
  File "/oldroot/home/humbert/dokumente/photovoltaik-wallbox/mytoyota/mytoyota/models/vehicle.py", line 107, in parallel_wrapper
    r = await function()
        ^^^^^^^^^^^^^^^^
  File "/oldroot/home/humbert/dokumente/photovoltaik-wallbox/mytoyota/mytoyota/api.py", line 135, in get_vehicle_electric_status_endpoint
    return await self._request_and_parse(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/oldroot/home/humbert/dokumente/photovoltaik-wallbox/mytoyota/mytoyota/api.py", line 49, in _request_and_parse
    return model(**response)
           ^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 2 validation errors for ElectricResponseModel
payload -> fuelLevel
  field required (type=value_error.missing)
payload -> fuelRange
  field required (type=value_error.missing)

Very well, 😊 These new error are due to the fact that we do not yet know all the API endpoints for all Toyota vehicles and their functions. We therefore still have to adapt some of our models. Please open a separate issue for better tracking.