Encoding problem, can't start home assistant anymore

Hey guys,

Yesterday I did some changes to my configuration. All worked well for the last 2 weeks until I did a restart after changing my configuration.yaml. If I try to run home assistant I get the following error:

    Traceback (most recent call last):
  File "/srv/homeassistant/bin/hass", line 11, in <module>
    sys.exit(main())
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/__main__.py", line 396, in main
    exit_code = setup_and_run_hass(config_dir, args)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/__main__.py", line 281, in setup_and_run_hass
    from homeassistant import bootstrap
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/bootstrap.py", line 19, in <module>
    from homeassistant.setup import async_setup_component
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py", line 14, in <module>
    import homeassistant.util.package as pkg_util
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/util/package.py", line 11, in <module>
    import pkg_resources
  File "/srv/homeassistant/lib/python3.4/site-packages/pkg_resources/__init__.py", line 72, in <module>
    import packaging.requirements
  File "/srv/homeassistant/lib/python3.4/site-packages/packaging/requirements.py", line 9, in <module>
    from pyparsing import stringStart, stringEnd, originalTextFor, ParseException
  File "/srv/homeassistant/lib/python3.4/site-packages/pyparsing.py", line 4734, in <module>
  File "/srv/homeassistant/lib/python3.4/site-packages/pyparsing.py", line 1261, in setParseAction
    self.parseAction = list(map(_trim_arity, list(fns)))
  File "/srv/homeassistant/lib/python3.4/site-packages/pyparsing.py", line 1043, in _trim_arity
    this_line = extract_stack(limit=2)[-1]
  File "/usr/lib/python3.4/traceback.py", line 301, in extract_stack
    stack = list(_extract_stack_iter(_get_stack(f), limit=limit))
  File "/usr/lib/python3.4/traceback.py", line 65, in _extract_tb_or_stack_iter
    line = linecache.getline(filename, lineno, f.f_globals)
  File "/usr/lib/python3.4/linecache.py", line 15, in getline
    lines = getlines(filename, module_globals)
  File "/usr/lib/python3.4/linecache.py", line 41, in getlines
    return updatecache(filename, module_globals)
  File "/usr/lib/python3.4/linecache.py", line 127, in updatecache
    lines = fp.readlines()
  File "/usr/lib/python3.4/codecs.py", line 313, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position 5135: invalid continuation byte

I think the problem is the last line. So I tried to re-save my configuration.yaml file to make sure that it is UTF-8 encoded, but still no luck. I also checked if there are no non ASCII characters so there are none. Now I have stripped my config to a minimum to ensure that no other files could throw this error but I just can’t figure out the problem.

I hope that someone can help me with this.

Jorik

I started getting errors like that aswell. It also happened after a full reboot. Turned out my sdcard had been corrupted, and lots of files got weird symbols in various places. I couldn´t even reinstall python since python itself was needed for the package manager.

I made a backup of the important files (to a usbstick) and started over on a different sdcard, which now works just fine.

That reminds me… time to turn off my PI and make another sdcard image. :wink:

I had a very similar problem with RaspberryPi. It was running without problems for more than a year, then strange things started happening. After investigation found out that random files got corrupted (replaced single characters) all over the file system. SD card was OK, I had to replace the RaspberryPi.

I forgot to mention, I was checking the integrity of system files with debsums tool.

Thanks for the feedback. I will try the program you mentioned. Pretty strange well, I only have the Raspberry for two months and I only run HA.

Ok, I found the corrupt files and they are all related to Python 2.7 and Lib_pypy. The last one is mainly used for HA I think and also matches the files in the error log. The only question is if there is a way to reinstall / rebuild the lib_pypy module.

Here are the failed files that debsums returned. (Thanks for the tip!)

/etc/skel/.bashrc                                                         FAILED
/usr/share/doc/cpio/changelog.gz                                          FAILED
/etc/dphys-swapfile                                                       FAILED
/etc/lightdm/lightdm.conf                                                 FAILED
/etc/lightdm/lightdm-gtk-greeter.conf                                     FAILED
/etc/login.defs                                                           FAILED
/etc/default/useradd                                                      FAILED
/usr/lib/pypy-upstream/lib-python/2.7/UserDict.pyc                        FAILED
/usr/lib/pypy-upstream/lib-python/2.7/bisect.pyc                          FAILED
/usr/lib/pypy-upstream/lib-python/2.7/code.pyc                            FAILED
/usr/lib/pypy-upstream/lib-python/2.7/codecs.pyc                          FAILED
/usr/lib/pypy-upstream/lib-python/2.7/codeop.pyc                          FAILED
/usr/lib/pypy-upstream/lib-python/2.7/collections.pyc                     FAILED
/usr/lib/pypy-upstream/lib-python/2.7/copy_reg.pyc                        FAILED
/usr/lib/pypy-upstream/lib-python/2.7/ctypes/__init__.pyc                 FAILED
/usr/lib/pypy-upstream/lib-python/2.7/ctypes/_endian.pyc                  FAILED
/usr/lib/pypy-upstream/lib-python/2.7/dis.pyc                             FAILED
/usr/lib/pypy-upstream/lib-python/2.7/distutils/__init__.pyc              FAILED
/usr/lib/pypy-upstream/lib-python/2.7/distutils/errors.pyc                FAILED
/usr/lib/pypy-upstream/lib-python/2.7/distutils/sysconfig.pyc             FAILED
/usr/lib/pypy-upstream/lib-python/2.7/distutils/sysconfig_cpython.pyc     FAILED
/usr/lib/pypy-upstream/lib-python/2.7/distutils/sysconfig_pypy.pyc        FAILED
/usr/lib/pypy-upstream/lib-python/2.7/encodings/__init__.pyc              FAILED
/usr/lib/pypy-upstream/lib-python/2.7/encodings/aliases.pyc               FAILED
/usr/lib/pypy-upstream/lib-python/2.7/encodings/utf_8.pyc                 FAILED
/usr/lib/pypy-upstream/lib-python/2.7/genericpath.pyc                     FAILED
/usr/lib/pypy-upstream/lib-python/2.7/heapq.pyc                           FAILED
/usr/lib/pypy-upstream/lib-python/2.7/inspect.pyc                         FAILED
/usr/lib/pypy-upstream/lib-python/2.7/keyword.pyc                         FAILED
/usr/lib/pypy-upstream/lib-python/2.7/linecache.pyc                       FAILED
/usr/lib/pypy-upstream/lib-python/2.7/opcode.pyc                          FAILED
/usr/lib/pypy-upstream/lib-python/2.7/os.pyc                              FAILED
/usr/lib/pypy-upstream/lib-python/2.7/posixpath.pyc                       FAILED
/usr/lib/pypy-upstream/lib-python/2.7/re.pyc                              FAILED
/usr/lib/pypy-upstream/lib-python/2.7/shlex.pyc                           FAILED
/usr/lib/pypy-upstream/lib-python/2.7/site.pyc                            FAILED
/usr/lib/pypy-upstream/lib-python/2.7/sre_compile.pyc                     FAILED
/usr/lib/pypy-upstream/lib-python/2.7/sre_constants.pyc                   FAILED
/usr/lib/pypy-upstream/lib-python/2.7/sre_parse.pyc                       FAILED
/usr/lib/pypy-upstream/lib-python/2.7/stat.pyc                            FAILED
/usr/lib/pypy-upstream/lib-python/2.7/string.pyc                          FAILED
/usr/lib/pypy-upstream/lib-python/2.7/sysconfig.pyc                       FAILED
/usr/lib/pypy-upstream/lib-python/2.7/tokenize.pyc                        FAILED
/usr/lib/pypy-upstream/lib-python/2.7/traceback.pyc                       FAILED
/usr/lib/pypy-upstream/lib-python/2.7/warnings.pyc                        FAILED
/usr/lib/pypy-upstream/lib-python/2.7/weakref.pyc                         FAILED
/usr/lib/pypy-upstream/lib_pypy/_ctypes/__init__.pyc                      FAILED
/usr/lib/pypy-upstream/lib_pypy/_ctypes/array.pyc                         FAILED
/usr/lib/pypy-upstream/lib_pypy/_ctypes/basics.pyc                        FAILED
/usr/lib/pypy-upstream/lib_pypy/_ctypes/builtin.pyc                       FAILED
/usr/lib/pypy-upstream/lib_pypy/_ctypes/dll.pyc                           FAILED
/usr/lib/pypy-upstream/lib_pypy/_ctypes/dummy.pyc                         FAILED
/usr/lib/pypy-upstream/lib_pypy/_ctypes/function.pyc                      FAILED
/usr/lib/pypy-upstream/lib_pypy/_ctypes/pointer.pyc                       FAILED
/usr/lib/pypy-upstream/lib_pypy/_ctypes/primitive.pyc                     FAILED
/usr/lib/pypy-upstream/lib_pypy/_ctypes/structure.pyc                     FAILED
/usr/lib/pypy-upstream/lib_pypy/_ctypes/union.pyc                         FAILED
/usr/lib/pypy-upstream/lib_pypy/_pypy_interact.pyc                        FAILED
/usr/lib/pypy-upstream/lib_pypy/_pypy_irc_topic.pyc                       FAILED
/usr/lib/pypy-upstream/lib_pypy/ctypes_config_cache/__init__.pyc          FAILED
/usr/lib/pypy-upstream/lib_pypy/ctypes_config_cache/_resource_32_.pyc     FAILED
/usr/lib/pypy-upstream/lib_pypy/ctypes_config_cache/_resource_cache.pyc   FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/__init__.pyc                       FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/commands.pyc                       FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/completing_reader.pyc              FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/console.pyc                        FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/curses.pyc                         FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/fancy_termios.pyc                  FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/historical_reader.pyc              FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/input.pyc                          FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/keymap.pyc                         FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/reader.pyc                         FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/readline.pyc                       FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/simple_interact.pyc                FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/unicodedata_.pyc                   FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/unix_console.pyc                   FAILED
/usr/lib/pypy-upstream/lib_pypy/pyrepl/unix_eventqueue.pyc                FAILED
/usr/share/doc/python-setuptools/formats.txt.gz                           FAILED
/usr/share/doc/python-setuptools/merge-faq.txt.gz                         FAILED