alandtse / alexa_media_player

This is a custom component to allow control of Amazon Alexa devices in Home Assistant using the unofficial Alexa API.
Apache License 2.0
1.53k stars 290 forks source link

"Config flow could not be loaded" / "bad marshal data" #2673

Closed yorb closed 1 week ago

yorb commented 2 weeks ago

IMPORTANT: Please search the issues, including closed issues, and the FAQ before opening a new issue. The template is mandatory; failure to use it will result in issue closure.

Describe the bug

After downloading from HACS and attempting to install the integration, the following error is shown:

Config flow could not be loaded: {"message":"Invalid handler specified"}

To Reproduce

  1. Uninstall AMP (if installed)
  2. (Optional) Delete AMP from HACS and remove all traces of AMP, including entries within .storage (pickle, config files), and restart
  3. Make sure AMP is downloaded from HACS (and restart if needed)
  4. Click 'Add Integration' and select AMP
  5. See error

Expected behavior

The setup config flow starts.

Screenshots

image

System details

Debug Logs (alexa_media & alexapy) Please provide logs.

  File "/usr/src/homeassistant/homeassistant/loader.py", line 1268, in _load_platform
    cache[full_name] = self._import_platform(platform_name)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1300, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, in protected_loop_func
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/config/custom_components/alexa_media/__init__.py", line 18, in <module>
    from alexapy import (
  File "/usr/local/lib/python3.12/site-packages/alexapy/__init__.py", line 16, in <module>
    from .alexaapi import AlexaAPI
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 23, in <module>
    from .alexalogin import AlexaLogin
  File "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py", line 35, in <module>
    from bs4 import BeautifulSoup
  File "/usr/local/lib/python3.12/site-packages/bs4/__init__.py", line 37, in <module>
    from .builder import (
  File "/usr/local/lib/python3.12/site-packages/bs4/builder/__init__.py", line 626, in <module>
    from . import _html5lib
  File "/usr/local/lib/python3.12/site-packages/bs4/builder/_html5lib.py", line 21, in <module>
    import html5lib
  File "/usr/local/lib/python3.12/site-packages/html5lib/__init__.py", line 25, in <module>
    from .html5parser import HTMLParser, parse, parseFragment
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 991, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1124, in get_code
  File "<frozen importlib._bootstrap_external>", line 753, in _compile_bytecode
ValueError: bad marshal data (invalid reference)

Note the logs above are without any AMP-specific logging added. If I add the logger config entry as per the link above, no errors are output at all since this is ERROR-level and comes from HA, not AMP. The FAQ should probably be updated to help users add logging for setup errors.

Additional context

I don't know when this started, but AMP was previously working just fine and one day I noticed it stopped (my devices were unavailable). I deleted and attempted to reinstall the integration and this started. I've tried removing all traces of AMP including deleting from HACS and redownloading (with several reboots in between), but the error is the same. So either there is some kind of critical bug in AMP setup (unlikely since this has been going on for weeks and no one else has reported it) or there is some leftover file in my installation that I don't know about. The "bad marshal data" seems like a generic python issue that is usually resolved by clearing out __pycache__, but since I've tried deleting AMP and redownloading it I'm not really sure where else it could be storing these binaries.

The UI error is the same as #2293, but the cause looks different so I'm creating a new issue.

danielbrunt57 commented 2 weeks ago

File "/config/custom_components/alexa_media/init.py", line 18, in from alexapy import ( File "/usr/local/lib/python3.12/site-packages/alexapy/init.py", line 16, in from .alexaapi import AlexaAPI File "/usr/local/lib/python3.12/site-packages/alexapy/alexaapi.py", line 23, in from .alexalogin import AlexaLogin File "/usr/local/lib/python3.12/site-packages/alexapy/alexalogin.py", line 35, in from bs4 import BeautifulSoup File "/usr/local/lib/python3.12/site-packages/bs4/init.py", line 37, in from .builder import ( File "/usr/local/lib/python3.12/site-packages/bs4/builder/init.py", line 626, in from . import _html5lib File "/usr/local/lib/python3.12/site-packages/bs4/builder/_html5lib.py", line 21, in import html5lib File "/usr/local/lib/python3.12/site-packages/html5lib/init.py", line 25, in from .html5parser import HTMLParser, parse, parseFragment

AMP is trying to import from the alexapy library and that seems to be where it's going south on you. Check pip show alexapy in the HA container. From SSH session to homeassisstant you can sudo docker exec -it homeassistant bash to get into the main container environment and that's where alexapy lives. The alexapy python package resides in /usr/local/lib/python/3.12/site-packages/alexapy and I suspect it's somehow messed up or missing. If it's there and pip shows the correct version then maybe deleting __pycache__ in that folder and restarting HA will resolve it...

yorb commented 2 weeks ago

@danielbrunt57 Thanks for the reply, that makes sense but so far I've only used the Terminal & SSH add-on which doesn't have docker, so from some googling it looks like I need to go a level deeper. Are these the instructions I should follow? I'm running HA OS on a pi, if it matters.

danielbrunt57 commented 2 weeks ago

I'm using the Terminal & SSH add-on and I'm running Home Assistant OS on HA "Blue" ODROID N2+ and I have the docker command. Have you tried the command via SSH and it failed?

danielbrunt57 commented 2 weeks ago

The instructions you reference allow you to access the host via external SSH on port 22222 thus bypassing the need to run sudo docker exec -t homeassistant bash from the standard SSH connection that takes you inside the Advanced SSH & Web Terminal add-on docker container which only exposes the config directory from the homeassistant container.

pappaloo commented 1 week ago

Same exact issue. I just did an upgrade to Alexapy (sudo pip install alexapy --upgrade), and restarted HA. Solved the issue, in case any others are running into this.

yorb commented 1 week ago

Finally getting back to this. Thanks @danielbrunt57, yes, I had tried docker and even just sudo and they weren't available, but that's because I was using Terminal & SSH, and not Advanced Terminal & SSH. The commands you provided worked fine in the second one. I imagine the external SSH instructions I found would have worked too, but just swapping one add-on for another was easy.

pip show alexapy indeed returned nothing, so I installed it as @pappaloo did and then re-added AMP and everything is working again. It seems like uninstalling AMP must have removed alexapy, and then reinstalling it for some reason did not reinstall alexapy. Not sure what happened there.

Thanks for your help!

danielbrunt57 commented 1 week ago

Always happy to help when I can!