import sys
msg = {'text': '\x826'}
sys.stderr.write('default encoding: %s\n' % sys.stdout.encoding)
encoding = sys.stdout.encoding or 'utf-8'
Redirecting python's stdout to the file fails with UnicodeEncodeError