Comment 14 for bug 1580728

Revision history for this message
ChangBo Guo(gcb) (glongwave) wrote :

Similar error like UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 386: ordinal not in range(128) usually occurred when sys.getdefaultencoding != 'utf-8".
defaultencoding is 'ascii' on Python 2, but 'uft-8' on Python 3 and there is now way to set on Python 3. So we prefer to use 'utf-8' on Python 2.

[changboguo@localhost oslo.log]$ python
Python 2.7.10 (default, Sep 24 2015, 17:50:09)
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'ascii'
>>>
[changboguo@localhost oslo.log]$ python3
Python 3.4.2 (default, Jul 9 2015, 17:24:30)
[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'
>>>

The following code may fix the issue.

import sys
default_encoding = 'utf-8'
if sys.getdefaultencoding() != default_encoding:
   reload(sys)
   sys.setdefaultencoding(default_encoding)