Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'token_version' #55

Closed
DavyRoswinkel opened this issue Jun 18, 2022 · 3 comments · Fixed by #56
Closed

KeyError: 'token_version' #55

DavyRoswinkel opened this issue Jun 18, 2022 · 3 comments · Fixed by #56

Comments

@DavyRoswinkel
Copy link

Like the release notes shows, I tried reinstalling the addon ( already 5 times) but it doesn't solve the error.

Add-on version: 2.2.2
 You are running the latest version of this add-on.
 System: Home Assistant OS 8.2  (aarch64 / raspberrypi4-64)
 Home Assistant Core: 2022.6.6
 Home Assistant Supervisor: 2022.05.3
[22:49:44] INFO: Strating Bridge...
2022-06-18 22:49:47 [INFO] Connecting mqtt
2022-06-18 22:49:47 [INFO] Starting loop
2022-06-18 22:49:47 [INFO] Logging in with credentials
2022-06-18 22:50:03 [INFO] Written tokens.json file to filesystem
2022-06-18 22:50:03 [INFO] Next run at 2022-06-18 22:53:21
2022-06-18 22:53:21 [DEBUG] Loop run started
Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/app/toogoodtogo_ha_mqtt_bridge/main.py", line 281, in loop
    if not is_latest_version():
  File "/app/toogoodtogo_ha_mqtt_bridge/main.py", line 161, in is_latest_version
    token_version = version.parse(tokens["token_version"])
KeyError: 'token_version'
@DavyRoswinkel
Copy link
Author

Correction!!! It does work...You need to let it run the loop again, then the issue is solved.

@MaxWinterstein
Copy link
Owner

In fact, there is some issue when the token file does not exist before.

Workaround:
As @DavyRoswinkel mentioned, you need to restart the add-on one time to make it work.

Reproduction:

$ rm data/tokens.json
$ python toogoodtogo_ha_mqtt_bridge/main.py
2022-06-19 06:42:46 [INFO] Connecting mqtt
2022-06-19 06:42:46 [INFO] Starting loop
2022-06-19 06:42:46 [INFO] Logging in with credentials
Check your mailbox on PC to continue... (Mailbox on mobile won't work, if you have installed tgtg app.)
Check your mailbox on PC to continue... (Mailbox on mobile won't work, if you have installed tgtg app.)
Check your mailbox on PC to continue... (Mailbox on mobile won't work, if you have installed tgtg app.)
Logged in!
2022-06-19 06:43:02 [INFO] Written tokens.json file to filesystem
2022-06-19 06:43:02 [INFO] Next run at 2022-06-19 06:44:35
2022-06-19 06:44:35 [DEBUG] Loop run started
Exception in thread Thread-3:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "toogoodtogo_ha_mqtt_bridge/main.py", line 281, in loop
    if not is_latest_version():
  File "toogoodtogo_ha_mqtt_bridge/main.py", line 161, in is_latest_version
    token_version = version.parse(tokens["token_version"])
KeyError: 'token_version'

^CException ignored in: <module 'threading' from '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py'>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 1273, in _shutdown
    t.join()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 1032, in join
    self._wait_for_tstate_lock()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 1048, in _wait_for_tstate_lock
    elif lock.acquire(block, timeout):
KeyboardInterrupt

@Dielee might genereate a quick fix for this? :)

@Dielee
Copy link
Collaborator

Dielee commented Jun 19, 2022

I will have a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants