flobz / psa_car_controller

Control psa car with connected_car v4 API.
GNU General Public License v3.0
423 stars 225 forks source link

Invalid grant - New code by SMS requested but no way to enter it #272

Closed christof62 closed 2 years ago

christof62 commented 2 years ago

Describe the bug After restart the psa car controller requests a new code by SMS and the server stops. Hence there is no way to enter the code. Containerized version as home assistant plugin. Same behavior with every restart of the plug in. With each restart I directly receive a SMS from PSA with the code. Need to reinstall the plugin to resolve the problem. Unfortunately all collected data gets lost.

To Reproduce Steps to reproduce the behavior:

  1. what command did you use? Re-starting the psa car controller plugin in home assistant.
  2. when the bug happend ? After restart the psa car controller. Before everything was working. Also restarts of the psa car controller worked OK with the same version of the psa car controller. With one recent restart the bug happend and persists.
  3. Does it persist after restarting the program? yes, with each start
  4. Does it persist after recreate config by going to http://server_address:port/config? The psa car controller starts but stops/crashes soon after starting. No chance to go to the config page.

Config file So far I don't know how to get access to files inside a home assistant addon.

Environment (please complete the following information):

HA Addon log:

Containerised psa_car_controller loading...
2021-11-11 09:27:37,928 :: INFO :: save config change
2021-11-11 09:27:38,405 :: INFO :: ["{'vin': '....', 'vehicle_id': '...', 'label': 'corsa-e', 'brand': 'C', 'abrp_name': 'opel:corsae:20:50', 'battery_power': 46, 'fuel_capacity': 0, 'max_elec_consumption': 70, 'max_fuel_consumption': 0}"]
2021-11-11 09:27:38,780 :: INFO :: save config change
2021-11-11 09:27:40,108 :: ERROR :: can't refresh_remote_token: {'error': 'invalid_grant', 'error_description': 'grant is invalid', 'refresh_token': 'c18ced78-6234-4115-8add-2bbdf84ad3db'}
 Create a new one
Traceback (most recent call last):
  File "/psa_car_controller/my_psacc.py", line 226, in get_otp_code
    otp_code = self.otp.get_otp_code()
  File "/psa_car_controller/otp/otp.py", line 277, in get_otp_code
    raise ConfigException("Can't get otp code")
otp.otp.ConfigException: Can't get otp code
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/psa_car_controller/server.py", line 22, in <module>
    conf.load_app()
  File "/psa_car_controller/libs/config.py", line 105, in load_app
    self.start_remote_control()
  File "/psa_car_controller/libs/config.py", line 63, in start_remote_control
    self.myp.start_mqtt()
  File "/psa_car_controller/my_psacc.py", line 336, in start_mqtt
    if self._refresh_remote_token():
  File "/psa_car_controller/my_psacc.py", line 273, in _refresh_remote_token
    otp_code = self.get_otp_code()
  File "/psa_car_controller/libs/utils.py", line 37, in wrapper
    return func(*args, **kwargs)
  File "/psa_car_controller/my_psacc.py", line 228, in get_otp_code
    self.load_otp(force_new=True)
  File "/psa_car_controller/my_psacc.py", line 209, in load_otp
    otp_session = new_otp_session(otp_session)
  File "/psa_car_controller/otp/otp.py", line 336, in new_otp_session
    otp.smsCode = input("What is the code you just received by SMS ?")
EOFError: EOF when reading a line
What is the code you just received by SMS ?
flobz commented 2 years ago

EOFError: EOF when reading a line This is the error, you need to start the image with - -web-conf argument

christof62 commented 2 years ago

you need to start the image with - -web-conf argument

Unfortunately I don't know how to do this in ha.

flobz commented 2 years ago

Give me the error that you have in ha if you want to use ha.

flobz commented 2 years ago

and use the issue template please.

christof62 commented 2 years ago

I gave the error. In my opinion it has nothing to do with ha. If you believe that the issue template will help I will recreate the issue.

flobz commented 2 years ago

Yes recreate or modify this issue please. I'm pretty sure that you don't have the same error in ha log.

christof62 commented 2 years ago

I did now restore my last addon backup and could reconfigure from there. So I just lost a view days of data. Nevertheless it would be very useful if the exception would not lead to a crash so that reconfiguration would be possible w/o the need to fall back to a previous backup.

flobz commented 2 years ago

Ok, the program can be run on a terminal. If you launch it in a terminal without the - - web-conf argument it will ask your password in that terminal. In the other hand if you start it in a container the program can't ask you the password because you don't have access to the container terminal. To sum up its normal to ha this error.

christof62 commented 2 years ago

So far understood. Nevertheless it would be much more convenient if the server would not stop execution with the exception but allow entering need data by the ui page. It is now the 4th time since I am using the psa car controller as ha addon that this issue occurs.

Do you have any idea what the root cause of the issue could be? As mentioned, it happens every now and then, but I could not see any pattern which triggered this.

However, thank you very much for your incredible and very valuable work!

flobz commented 2 years ago

if the server would not stop execution with the exception You need to give me the log. I can fix something without it. The log you give me aren't from ha add-ons.

christof62 commented 2 years ago

The log you give me aren't from ha add-ons.

What do you mean with this? Definitely the provided log is from the ha add-on. And the same was logged with each restart.

flobz commented 2 years ago

Ok sorry, I thought that log didn't came from ha. I look at the issue.

Profil404 commented 2 years ago

+1, same problem here

flobz commented 2 years ago

try version 2.6.0 please.

Profil404 commented 2 years ago

Seem to be fixed 👍