UnicodeDecodeError: 'utf8' codec can't decode byte 0x96 in position 1054: invalid start byte

I have been getting some really weird messages. After I install my product theme (theme.fipp) and I try to use @@manage-viewlets to it, the following error message occur. Note that I am using Plone 5.1.0:

2018-04-05 14:38:16 INFO Zope Ready to handle requests
2018-04-05 14:38:24 ERROR plone.app.viewletmanager Error while rendering viewlet-manager=plone.belowcontenttitle, viewlet=plone.belowcontenttitle.documentbyline
Traceback (most recent call last):
File "/var/plone/testservices/buildout-cache/eggs/plone.app.viewletmanager-2.0.11-py2.7.egg/plone/app/viewletmanager/manager.py", line 112, in render
html.append(viewlet.render())
File "/var/plone/testservices/buildout-cache/eggs/plone.app.layout-2.7.5-py2.7.egg/plone/app/layout/viewlets/common.py", line 59, in render
return self.index()
File "/var/plone/testservices/buildout-cache/eggs/z3c.jbot-0.7.2-py2.7.egg/z3c/jbot/patches.py", line 83, in five_get_and_bind
inst.read()
File "/var/plone/testservices/buildout-cache/eggs/zope.pagetemplate-4.2.1-py2.7.egg/zope/pagetemplate/pagetemplate.py", line 183, in read
self._cook_check()
File "/var/plone/testservices/buildout-cache/eggs/Products.CMFPlone-5.1.0.1-py2.7.egg/Products/CMFPlone/patches/templatecookcheck.py", line 23, in cook_check
text, type
= self._read_file()
File "/var/plone/testservices/buildout-cache/eggs/zope.pagetemplate-4.2.1-py2.7.egg/zope/pagetemplate/pagetemplatefile.py", line 87, in read_file
text, type
= self._prepare_html(text)
File "/var/plone/testservices/buildout-cache/eggs/zope.pagetemplate-4.2.1-py2.7.egg/zope/pagetemplate/pagetemplatefile.py", line 73, in _prepare_html
text = text.decode(encoding)
File "/var/plone/testservices/zeocluster/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x96 in position 1054: invalid start byte
2018-04-05 14:38:27 ERROR plone.app.viewletmanager Error while rendering viewlet-manager=plone.belowcontenttitle, viewlet=plone.belowcontenttitle.documentbyline
Traceback (most recent call last):
File "/var/plone/testservices/buildout-cache/eggs/plone.app.viewletmanager-2.0.11-py2.7.egg/plone/app/viewletmanager/manager.py", line 112, in render
html.append(viewlet.render())
File "/var/plone/testservices/buildout-cache/eggs/plone.app.layout-2.7.5-py2.7.egg/plone/app/layout/viewlets/common.py", line 59, in render
return self.index()
File "/var/plone/testservices/buildout-cache/eggs/z3c.jbot-0.7.2-py2.7.egg/z3c/jbot/patches.py", line 83, in five_get_and_bind
inst.read()
File "/var/plone/testservices/buildout-cache/eggs/zope.pagetemplate-4.2.1-py2.7.egg/zope/pagetemplate/pagetemplate.py", line 183, in read
self._cook_check()
File "/var/plone/testservices/buildout-cache/eggs/Products.CMFPlone-5.1.0.1-py2.7.egg/Products/CMFPlone/patches/templatecookcheck.py", line 23, in cook_check
text, type
= self._read_file()
File "/var/plone/testservices/buildout-cache/eggs/zope.pagetemplate-4.2.1-py2.7.egg/zope/pagetemplate/pagetemplatefile.py", line 87, in read_file
text, type
= self._prepare_html(text)
File "/var/plone/testservices/buildout-cache/eggs/zope.pagetemplate-4.2.1-py2.7.egg/zope/pagetemplate/pagetemplatefile.py", line 73, in _prepare_html
text = text.decode(encoding)
File "/var/plone/testservices/zeocluster/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x96 in position 1054: invalid start byte

I have also noticed that there is a new line added to the top line of the file that says, "# -- coding: utf-8 --" to the following files. I can't seem to get rid of it:

src/theme/fipp/setuphandlers.py
src/theme/fipp/init.py
src/theme/fipp/tests/test_setup.py
src/theme/fipp/tests/test_robot.py

Please advise. Thanks so much.

Some page template file is obviously not using utf8 as encoding. Either use the debugger or add some logging code for figuring out the offending .pt file...or check your .pt files UTF8 compatibility.

1 Like

Thanks Andreas, I found the culprit by using the file --mime command:

$ file --mime plone.app.layout.viewlets.document_byline.pt
plone.app.layout.viewlets.document_byline.pt: text/html; charset=unknown-8bit

Once the file was resaved with encoding utf-8, the errors disappeared. Thanks so much! :slight_smile:

1 Like