Broken integrations

Hi,

I’m running HA OS on a VM on my Linux server. Recently, I see quite a few errors in log:

Unexpected error importing (platform component).

And in all cases, the stack trace ends with

ValueError: bad marshal data (unknown type code)

Any idea what that is? Might my Python installation be broken? Any way to fix something like this?

Thanks

If you are running HAOS you don’t need to worry about your python being out of date.

Some proper error messages would help though.

Hi,

not being out of date, but broken - the ValueError sounds pretty bad…

Below are two complete log entries (out of 6 a the moment) - thanks for helping!

Best
Christian

Logger: homeassistant.loader
Source: components/rest/__init__.py:7
First occurred: 6. November 2022 um 17:33:34 (1 occurrences)
Last logged: 6. November 2022 um 17:33:34

Unexpected exception importing platform homeassistant.components.rest.sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 722, in get_platform
    cache[full_name] = self._import_platform(platform_name)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 739, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/src/homeassistant/homeassistant/components/rest/__init__.py", line 7, in <module>
    import httpx
  File "/usr/local/lib/python3.10/site-packages/httpx/__init__.py", line 2, in <module>
    from ._api import delete, get, head, options, patch, post, put, request, stream
  File "/usr/local/lib/python3.10/site-packages/httpx/_api.py", line 4, in <module>
    from ._client import Client
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 29, in <module>
    from ._transports.default import AsyncHTTPTransport, HTTPTransport
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 30, in <module>
    import httpcore
  File "/usr/local/lib/python3.10/site-packages/httpcore/__init__.py", line 1, in <module>
    from ._api import request, stream
  File "/usr/local/lib/python3.10/site-packages/httpcore/_api.py", line 5, in <module>
    from ._sync.connection_pool import ConnectionPool
  File "/usr/local/lib/python3.10/site-packages/httpcore/_sync/__init__.py", line 4, in <module>
    from .http_proxy import HTTPProxy
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 879, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1012, in get_code
  File "<frozen importlib._bootstrap_external>", line 672, in _compile_bytecode
ValueError: bad marshal data (unknown type code)
Logger: homeassistant.loader
Source: components/tuya/__init__.py:7
First occurred: 6. November 2022 um 17:33:36 (1 occurrences)
Last logged: 6. November 2022 um 17:33:36

Unexpected exception importing component homeassistant.components.tuya
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 703, in get_component
    cache[self.domain] = importlib.import_module(self.pkg_path)
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/src/homeassistant/homeassistant/components/tuya/__init__.py", line 7, in <module>
    from tuya_iot import (
  File "/usr/local/lib/python3.10/site-packages/tuya_iot/__init__.py", line 2, in <module>
    from .device import TuyaDevice, TuyaDeviceListener, TuyaDeviceManager
  File "/usr/local/lib/python3.10/site-packages/tuya_iot/device.py", line 11, in <module>
    from .openmq import TuyaOpenMQ
  File "/usr/local/lib/python3.10/site-packages/tuya_iot/openmq.py", line 14, in <module>
    from paho.mqtt import client as mqtt
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 72, in <module>
    import dns.resolver
  File "/usr/local/lib/python3.10/site-packages/dns/resolver.py", line 38, in <module>
    import dns.query
  File "/usr/local/lib/python3.10/site-packages/dns/query.py", line 52, in <module>
    import httpx
  File "/usr/local/lib/python3.10/site-packages/httpx/__init__.py", line 2, in <module>
    from ._api import delete, get, head, options, patch, post, put, request, stream
  File "/usr/local/lib/python3.10/site-packages/httpx/_api.py", line 4, in <module>
    from ._client import Client
  File "/usr/local/lib/python3.10/site-packages/httpx/_client.py", line 29, in <module>
    from ._transports.default import AsyncHTTPTransport, HTTPTransport
  File "/usr/local/lib/python3.10/site-packages/httpx/_transports/default.py", line 30, in <module>
    import httpcore
  File "/usr/local/lib/python3.10/site-packages/httpcore/__init__.py", line 30, in <module>
    from ._sync import (
  File "/usr/local/lib/python3.10/site-packages/httpcore/_sync/__init__.py", line 4, in <module>
    from .http_proxy import HTTPProxy
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 879, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1012, in get_code
  File "<frozen importlib._bootstrap_external>", line 672, in _compile_bytecode
ValueError: bad marshal data (unknown type code)

I found a solution: Apparently indeed the Python installation HA is running against has issues - in particular, it seems that some .pyc files got corrupted for whatever reason.

Logging into the HomeAssistant Docker container and running find /usr -name '*.pyc' -delete fixed the issue, but might not be the way to go in the long run, since apparently Python scripts are loading slower now. There should be a way to recreate the files (have to do more research on that).

Or is there a way to tell docker to re-download and/or reinstall the homeassistant docker image?

Just rm the image and the container and start the container again.

Would you mind providing the necessary Docker commands? Thanks…

From memory

docker stop homeassistant
docker rm homeassistant
docker image prune

Then use the command that installed homeassistant again.