1. Solution exception:'ascii' codec can't encode character '\u5B8B' in position 106: ordinal not in range(128)

I open the offical example gh file,but the component"butterfly_blockMesh" turns wrong, and it shows “1. Solution exception:‘ascii’ codec can’t encode character ‘\u5B8B’ in position 106: ordinal not in range(128)”.Except my system name has Chinese character ,there is no Chinese character in that file.So how can I solve this problem?

1 Like

Try setting the system default encoding as utf-8 at the start of the script, so that all strings are encoded using that.

Example -

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

The above should set the default encoding as utf-8 .

In most cases, the issue is that when you call str(), python uses the default character encoding to try and encode the bytes you gave it, which in your case are sometimes representations of unicode characters. To fix the problem, you have to tell python how to deal with the string you give it by using .encode(‘whatever_unicode’). Most of the time, you should be fine using utf-8. So, stop using str() to convert from unicode to encoded text / bytes, properly use .encode() to encode the string:,

yourstring.encode('utf-8')

For python 3.x ,there is default encoding, hence there will be no issue of encoding.

1 Like

Check the input epw file path. If the file path have Chinese character, it will also show the same error.

Hi I am also having the following error text what could be the problem? thanks.

1.1. Solution exception:‘ascii’ codec can’t encode character ‘\u131’ in position 189: ordinal not in range(128)