Fatal Python error: initsite

Hello,

I recently updated my Hassio installation to 103.5.
This morning I noticed that my installation could no longer contact external url’s (such as the weather information). Then I tried rebooting my system, but it will no longer start.
Checking the logs I see the following:

Error: Fatal Python error: initsite: Failed to import the site module
Error processing line 1 of /usr/local/lib/python3.7/site-packages/google_api_core-1.15.0-py3.8-nspkg.pth:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site.py", line 168, in addpackage
    exec(line)
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.7/importlib/util.py", line 14, in <module>
    from contextlib import contextmanager
  File "/usr/local/lib/python3.7/contextlib.py", line 6, in <module>
    from functools import wraps
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 724, in exec_module
  File "<frozen importlib._bootstrap_external>", line 857, in get_code
  File "<frozen importlib._bootstrap_external>", line 525, in _compile_bytecode
ValueError: bad marshal data (unknown type code)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site.py", line 579, in <module>
    main()
  File "/usr/local/lib/python3.7/site.py", line 566, in main
    known_paths = addsitepackages(known_paths)
  File "/usr/local/lib/python3.7/site.py", line 349, in addsitepackages
    addsitedir(sitedir, known_paths)
  File "/usr/local/lib/python3.7/site.py", line 207, in addsitedir
    addpackage(sitedir, name, known_paths)
  File "/usr/local/lib/python3.7/site.py", line 178, in addpackage
    import traceback
  File "/usr/local/lib/python3.7/traceback.py", line 5, in <module>
    import linecache
  File "/usr/local/lib/python3.7/linecache.py", line 8, in <module>
    import functools
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 724, in exec_module
  File "<frozen importlib._bootstrap_external>", line 857, in get_code
  File "<frozen importlib._bootstrap_external>", line 525, in _compile_bytecode
ValueError: bad marshal data (unknown type code)

This is my setup info:

~ $ hassio homeassistant info
arch: armv7
boot: true
custom: false
image: homeassistant/raspberrypi3-homeassistant
ip_address: 172.30.32.1
last_version: 0.103.5
machine: raspberrypi3
port: 8123
ssl: true
version: 0.103.5
wait_boot: 600
watchdog: true

Any suggestions on how to solve this?

Thanks in advance.

Bart

Is your Rpi blocked after update?
Firewall? Connection lost?

Run on CLI nslookup google.com

This is the output of the nslookup:

~ $ nslookup google.com
Server:         127.0.0.11
Address:        127.0.0.11#53

Non-authoritative answer:
Name:   google.com
Address: 172.217.17.142
Name:   google.com
Address: 2a00:1450:400e:808::200e

So you have an internet connection.
What’s about your credentials to your external api’s ?

Would also try to update the supervisor and hassOS (host - system).

I slimmed down my configuration.yaml to only contain the following:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

http:
  base_url: !secret base_url
  ssl_certificate: /ssl/fullchain.pem
  ssl_key: /ssl/privkey.pem

zwave:
  usb_path: /dev/ttyACM0

And restarted homeassistant (hassio homeassistant restart), but problem remains.

I tried updating the supervisor (hassio supervisor update), but this is already at latest:

$ hassio supervisor update
Processing... Done.

Error: Version 193 is already in use

After running hassio hassos update, the update started, ssh connection went down and after a while the ssh connection was back. Checking the hassos version states:

~ $ hassio hassos info
board: rpi3
version: "3.7"
version_cli: "15"
version_cli_latest: "15"
version_latest: "3.7"

Checking the homeassistant logs, didn’t show any errors anymore. But my instance was still not available via duckdns. Then I tried to restart homeassistant, and the same error shows in the logs, preventing a full start of homeassistant:

~ $ hassio homeassistant restart
Processing... Done.

Error: Unknown Error, see logs
~ $ hassio homeassistant logs
sFatal Python error: initsite: Failed to import the site module
Error processing line 1 of /usr/local/lib/python3.7/site-packages/google_api_core-1.15.0-py3.8-nspkg.pth:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site.py", line 168, in addpackage
    exec(line)
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.7/importlib/util.py", line 14, in <module>
    from contextlib import contextmanager
  File "/usr/local/lib/python3.7/contextlib.py", line 6, in <module>
    from functools import wraps
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 724, in exec_module
  File "<frozen importlib._bootstrap_external>", line 857, in get_code
  File "<frozen importlib._bootstrap_external>", line 525, in _compile_bytecode
ValueError: bad marshal data (unknown type code)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site.py", line 579, in <module>
    main()
  File "/usr/local/lib/python3.7/site.py", line 566, in main
    known_paths = addsitepackages(known_paths)
  File "/usr/local/lib/python3.7/site.py", line 349, in addsitepackages
    addsitedir(sitedir, known_paths)
  File "/usr/local/lib/python3.7/site.py", line 207, in addsitedir
    addpackage(sitedir, name, known_paths)
  File "/usr/local/lib/python3.7/site.py", line 178, in addpackage
    import traceback
  File "/usr/local/lib/python3.7/traceback.py", line 5, in <module>
    import linecache
  File "/usr/local/lib/python3.7/linecache.py", line 8, in <module>
    import functools
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 724, in exec_module
  File "<frozen importlib._bootstrap_external>", line 857, in get_code
  File "<frozen importlib._bootstrap_external>", line 525, in _compile_bytecode
ValueError: bad marshal data (unknown type code)

What strikes me is the two different Python versions in the error log:

usr/local/lib/python3.7/site-packages/google_api_core-1.15.0-py3.8-nspkg.pth

Could this be an issue?

This issue seems to be caused because PEP 552 has been implemented, which adds extra 4 bytes to the .pyc header; but this version of setuptools is not aware of that yet. I think setuptools should be updated to v38.4.1.

See these links for further information on this bug:

Normally this should be fixable using:

sudo pip3 install --upgrade --force-reinstall setuptools

But I don’t know how to run this inside the restricted hassio environment.
Would anyone know how to install the setuptools update?