Comment 2 for bug 827090

Revision history for this message
Rex Tsai (chihchun) wrote : Re: apport-cli crashed with UnicodeEncodeError in communicate(): 'ascii' codec can't encode characters in position 40-42: ordinal not in range(128)

By default, the python 2.7 on Ubuntu/Debian is using ascii as default encoding. There is an option in /usr/lib/python2.7/site.py, user can enable to support locale aware default string encodings, which is a system wide setting.

The better approach is to switch the default encoding to user's setting. Like

import locale
encoding = 'ascii'
loc = locale.getdefaultlocale()
if loc[1]:
    encoding = loc[1]

sys.setdefaultencoding(encoding)