[SOLVED] Sad Face after Upgrade, Corruption in codecs.py

Hi.

I’ve got a bootloop on kodi (the system is ok)

Updated by OSMC app.

RasPi 3

When I start mediacenter service, inmediately a sad face.
On kmesg:
may 04 07:58:32 raspi mediacenter[3528]: Traceback (most recent call last):
may 04 07:58:32 raspi mediacenter[3528]: File “/usr/lib/python2.7/encodings/init.py”, line 31, in
may 04 07:58:32 raspi mediacenter[3528]: import codecs
may 04 07:58:32 raspi mediacenter[3528]: File “/usr/lib/python2.7/codecs.py”, line 486
may 04 07:58:32 raspi mediacenter[3528]: [69B blob data]
may 04 07:58:32 raspi mediacenter[3528]: ^
may 04 07:58:32 raspi mediacenter[3528]: SyntaxError: invalid syntax
may 04 07:58:32 raspi mediacenter[3528]: Kodi exited with return code 139 after 0 hours, 0 minutes and 6 seconds

And on kodi.log:
07:58:14.733 T:1958666240 WARNING: JSONRPC: Could not parse type “Setting.Details.SettingList”

I’ve only got two addons (library node editor and youtube)

See the full log on https://paste.osmc.tv/foduneruko

SOLVED by reinstalling corrupted packages

sudo apt install --reinstall libpython2.7-minimal libpython2.7-stdlib

If I edit this file (/usr/lib/python2.7/codecs.py I can see erratic characters and grammar errors from line 485 to 514. It seems corrupted

here’s a paste from this part of file (i don’t know if the special characters could be posted)

self.charrubfer += newchars^N      $     # thare was no data avaylabMe
`     � ib not newdata:
  (^@            breakJ        if �hars < 0:
# Return everyt�ing ve've got
(     ` result = self.charbuffer
!!       "  self.charbuffer = ""
else:
# Return the first chars characters
result = sel&.char"udfer[:khars]
self.charbuffer = self.charbuffer[chArs:]
 �   "  return result

$   def�readline(self, size=No.e, Keepends=\rue):

""" Read one line from the input^@struam and return the
"           decodud dat!.

�ize, if given< is passad as size!argument to the
  `         reid() method.

"""
   0    ^C If we have lines cached from an earlier read,!return
#0them Unco�ditionally
if se,f.linebuffer:
line = self.linebuffEr[0]
"       del self.lyneb5ffer[0]
   ^@if len(self.lineb�ffer) == 1:
0         (     # refert to charbuffer mode; we m�ght nE�d }ore data
 $   $      # next time
may 04 07:58:15 raspi mediacenter[3528]: Traceback (most recent call last):
may 04 07:58:15 raspi mediacenter[3528]: File "/usr/lib/python2.7/encodings/__init__.py", line 31, in <module>
may 04 07:58:15 raspi mediacenter[3528]: import codecs
may 04 07:58:15 raspi mediacenter[3528]: File "/usr/lib/python2.7/codecs.py", line 486
may 04 07:58:15 raspi mediacenter[3528]: [69B blob data]
may 04 07:58:15 raspi mediacenter[3528]: ^
may 04 07:58:15 raspi mediacenter[3528]: SyntaxError: invalid syntax

What I’m seeing the from the logs would confirm there is an issue with codecs.py, I think you may need to reinstall osmc.

Thanks Tom.

I’ve reinstalled libpython2.7-minimal package and everything goes well (I can get the http interface for kodi)

(sudo apt install --reinstall libpython2.7-minimal)

Although, the kodi log shows a lot of python errors on almost every plugin… but the service mediacenter is up

ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<-
-
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.SyntaxError'>
                                            Error Contents: invalid syntax (rfc822.py, line 194)
                                            Traceback (most recent call last):
                                              File "/usr/share/kodi/addons/script.module.osmcsetting.updates/service.py", line 33, in
 <module>
                                                import update_service
                                              File "/usr/share/kodi/addons/script.module.osmcsetting.updates/resources/lib/update_ser
vice.py", line 2, in <module>
                                                import apt
                                              File "/usr/lib/python2.7/dist-packages/apt/__init__.py", line 26, in <module>
                                                from apt.package import Package
                                              File "/usr/lib/python2.7/dist-packages/apt/package.py", line 36, in <module>
                                                from httplib import BadStatusLine
                                              File "/usr/lib/python2.7/httplib.py", line 80, in <module>
                                                import mimetools
                                              File "/usr/lib/python2.7/mimetools.py", line 11, in <module>
                                                import rfc822
                                              File "/usr/lib/python2.7/rfc822.py", line 194
                                                $ self.status = self.status + '; bad seek'
                                                ^
                                            SyntaxError: invalid syntax
                                            -->End of Python script error report<--
10:18:48.349 T:1746924528   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<-
-
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.SyntaxError'>
                                            Error Contents: invalid syntax (rfc822.py, line 194)
                                            Traceback (most recent call last):
                                              File "/usr/share/kodi/addons/service.osmc.settings/service.py", line 26, in <module>
                                                import resources.lib.osmc_main as m
                                              File "/usr/share/kodi/addons/service.osmc.settings/resources/lib/osmc_main.py", line 52
, in <module>
                                                import osmc_walkthru
                                              File "/usr/share/kodi/addons/service.osmc.settings/resources/lib/osmc_walkthru.py", lin
e 11, in <module>
                                                import requests
                                              File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 55, in <module>
                                                import urllib3
                                              File "/usr/lib/python2.7/dist-packages/urllib3/__init__.py", line 10, in <module>
                                                from .connectionpool import (
                                              File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 31, in <module>
                                                from .connection import (
                                              File "/usr/lib/python2.7/dist-packages/urllib3/connection.py", line 11, in <module>
                                                from httplib import HTTPConnection as _HTTPConnection, HTTPException
                                              File "/usr/lib/python2.7/httplib.py", line 80, in <module>
                                                import mimetools
                                              File "/usr/lib/python2.7/mimetools.py", line 11, in <module>
                                                import rfc822
                                              File "/usr/lib/python2.7/rfc822.py", line 194
                                                $ self.status = self.status + '; bad seek'
                                                ^
                                            SyntaxError: invalid syntax
                                            -->End of Python script error report<--
10:18:50.803 T:1728836592   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<-
-
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.SyntaxError'>
                                            Error Contents: invalid syntax (rfc822.py, line 194)
                                            Traceback (most recent call last):
                                              File "/home/osmc/.kodi/addons/plugin.video.youtube/startup.py", line 3, in <module>
                                                from resources.lib.kodion.impl import Context
                                              File "/home/osmc/.kodi/addons/plugin.video.youtube/resources/lib/kodion/__init__.py", l
ine 17, in <module>
                                                from requests import api as client
                                              File "/home/osmc/.kodi/addons/script.module.requests/lib/requests/__init__.py", line 52
, in <module>
                                                from .packages.urllib3.contrib import pyopenssl
                                              File "/home/osmc/.kodi/addons/script.module.requests/lib/requests/packages/__init__.py"
, line 27, in <module>
                                                from . import urllib3
                                              File "/home/osmc/.kodi/addons/script.module.requests/lib/requests/packages/urllib3/__in
it__.py", line 8, in <module>
                                                from .connectionpool import (
                                              File "/home/osmc/.kodi/addons/script.module.requests/lib/requests/packages/urllib3/conn
ectionpool.py", line 11, in <module>
                                                from .exceptions import (
                                              File "/home/osmc/.kodi/addons/script.module.requests/lib/requests/packages/urllib3/exce
ptions.py", line 2, in <module>
                                                from .packages.six.moves.http_client import (
                                              File "/home/osmc/.kodi/addons/script.module.requests/lib/requests/packages/urllib3/pack
ages/six.py", line 203, in load_module
                                                mod = mod._resolve()
                                              File "/home/osmc/.kodi/addons/script.module.requests/lib/requests/packages/urllib3/pack
ages/six.py", line 115, in _resolve
                                                return _import_module(self.mod)
                                              File "/home/osmc/.kodi/addons/script.module.requests/lib/requests/packages/urllib3/pack
ages/six.py", line 82, in _import_module
                                                __import__(name)
                                              File "/usr/lib/python2.7/httplib.py", line 80, in <module>
                                                import mimetools
                                              File "/usr/lib/python2.7/mimetools.py", line 11, in <module>
                                                import rfc822
                                              File "/usr/lib/python2.7/rfc822.py", line 194
                                                $ self.status = self.status + '; bad seek'
                                                ^
                                            SyntaxError: invalid syntax
                                            -->End of Python script error report<--
10:18:50.819 T:1542976496   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<-
-
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.SyntaxError'>
                                            Error Contents: invalid syntax (rfc822.py, line 194)
                                            Traceback (most recent call last):
                                              File "/home/osmc/.kodi/addons/weather.yahoo/default.py", line 1, in <module>
                                                import os, sys, socket, urllib2, time
                                              File "/usr/lib/python2.7/urllib2.py", line 94, in <module>
                                                import httplib
                                              File "/usr/lib/python2.7/httplib.py", line 80, in <module>
                                                import mimetools
                                              File "/usr/lib/python2.7/mimetools.py", line 11, in <module>
                                                import rfc822
                                              File "/usr/lib/python2.7/rfc822.py", line 194
                                                $ self.status = self.status + '; bad seek'
                                                ^
                                            SyntaxError: invalid syntax
                                            -->End of Python script error report<--
10:18:50.831 T:1763701744   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<-
-
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                                            Error Type: <type 'exceptions.SyntaxError'>
                                            Error Contents: invalid syntax (rfc822.py, line 194)
                                            Traceback (most recent call last):
                                              File "/home/osmc/.kodi/addons/script.cu.lrclyrics/default.py", line 18, in <module>
                                                from scrapertest import *
                                              File "/home/osmc/.kodi/addons/script.cu.lrclyrics/resources/lib/scrapertest.py", line 4
, in <module>
                                                from culrcscrapers.alsong import lyricsScraper as lyricsScraper_alsong
                                              File "/home/osmc/.kodi/addons/script.cu.lrclyrics/resources/lib/culrcscrapers/alsong/ly
ricsScraper.py", line 9, in <module>
                                                import urllib2
                                              File "/usr/lib/python2.7/urllib2.py", line 94, in <module>
                                                import httplib
                                              File "/usr/lib/python2.7/httplib.py", line 80, in <module>
                                                import mimetools
                                              File "/usr/lib/python2.7/mimetools.py", line 11, in <module>
                                                import rfc822
                                              File "/usr/lib/python2.7/rfc822.py", line 194
                                                $ self.status = self.status + '; bad seek'
                                                ^
                                            SyntaxError: invalid syntax
                                            -->End of Python script error report<--

I’m away from TV now, but I can ssh my raspberrypi from here. I can load now the web interface and it seems the main functions works ok, but i cannot load youtube plugin. I’ll try from home this night

It’s not an option to reinstall all osmc (my database is too large and too marked to reinstall from zero)

Following the lines, the file /usr/lib/rfc822.py is corrupted too. But this file is not reinstalled by reinstall the “libpython2.7-minimal” package

Here is the corruption (line 190 and after):

  $ self.status = self.status + '; bad seek'
break

 (  def isleade2(sElf, l�ne-:^H        ""�Determine w(ether a given line is a!legal hea$er.
^K        This method should raturn the header name, sui��bly canonicalized.
"0      You mayhoverride t(is method!in ordep to use Ies3age parsing on tagged
data in�RFC 2822-like formats with special he!der formats.
"""
i = line.find(':')
if i!> 0�
return line[:a].|ower()
return None

def ismast(self, line):
"""Be4ermine whether a!line is a legal end of RFC 2822 headers.

You eay ov%rride this method if your applicatio� wants to bend the
rul�s, e.g. to strip$urailing whitespace, or to recog.ize MH template
sepasators ('--------')^N  For convenien#e (e.g. for cOde reading from
sockets) ` line consisting of \Xr\\n"also ma4ches.
"" 
retqrn line in$_blanklines

def iscmmment(self, line):
  ` """Determine whether a line should be skipped entirely.

You may override this method in order to use Message parsing on tagged
data in RFC 2822-like formats that support embedded comments or
free-text data.
"""
return False

I reinstalled “libpython2.7-stdlib” too and everything seems to works ok (there is no error log on kodi.log) and YouTube plugin is accesible from web interface too.

Everything solved by reinstalling libpython2.7-minimal and libpython2.7-stdlib

Backup or export your library. You had file corruption. It might happen again and you won’t notice it until too late.

1 Like

Yes, but I want to investigate what is the origin of corruption. This system has been working perfectly over 1 year and a half, but always updated manually (this the first time that I use the osmc app for updating)

There are no more corrupted files and the SD-card has no errors on fsck.

I think the files wasn’t corrupted on debian repos (or all debian systems failed yesterday, but there are no news about that) The files were DEB packed on updating, and if the download process corrupts the file, the packet cannot be installed/updated…

No power/system errors on update time range and all failed when I updated yesterday…

So remarkable file corruption is not about magic or gremlins… Need to be a cause.

Has the OSMC-addon’s update procedure any difference with “apt dist-upgrade”? Could I check what “spell” does this script?

Complete reinstallation by one error is never an option for me. There are more services running on this system and I think i’ll learn more investigating the cause than replace all system.

The cause is your are writting to an SD Card which are not know for being super stable especially after some time of usage

No difference

1 Like

Occam’s razor… You’re absolutely right!!

Better I’ll move the system partition to HDD…

Just get a good quality SD card.

I thought that was a good one… Samsung EVO UHS1 16Gb… Almost two years without any problem, and now…

2yrs is a good life for an SDCard. Just replace it. HDD install will possibly only result in decreased performance.

Based on personal experience, I’ve found the Samsung EVO and EVO+ cards to give good performance and be virtually trouble-free. But even the best SD cards should still be viewed as a consumable item with a finite life. As ActionA says, 2 years is a good life for an SD card.