Skip to content. | Skip to navigation

Personal tools
Log in
Sections
You are here: Home Python 2.7 UnicodeDecodeError upgrading to Ubuntu 18.04 LTS

Python 2.7 UnicodeDecodeError upgrading to Ubuntu 18.04 LTS

published May 03, 2018 07:39   by admin ( last modified May 03, 2018 07:39 )

Summary

Use

import sys
reload(sys) 
sys.setdefaultencoding('utf8')

Longer explanation (or at least more text)

A python script stopped working when upgrading from Ubuntu 17.10 to 18.04LTS. It was still running under python 2.7 but it now had the dreaded UnicodeDecodeError. Why?

Well, who knows, but a possibilty is that Ubuntu has stopped setting a default encoding. The solution is as above.

from __future__ import unicode_literals

…did not work since that made things such as

d.isoformat(' ')

 

stop working complaining about there being unicode.