UnicodeEncodeError: 'ascii' codec can't encode character '\U0001f680' in position 361: ordinal not in range(128)

Traceback (most recent call last): File “/usr/local/lib/python3.6/dist-packages/rasa/cli/x.py”, line 431, in run_locally args, project_path, args.data, token=rasa_x_token, config_path=config_path File “/usr/local/lib/python3.6/dist-packages/rasax/community/local.py”, line 192, in main rasa_cli_utils.print_success(“Starting Rasa X in local mode… \U0001f680”) File “/usr/local/lib/python3.6/dist-packages/rasa/cli/utils.py”, line 222, in print_success print_color(*args, color=bcolors.OKGREEN) File “/usr/local/lib/python3.6/dist-packages/rasa/cli/utils.py”, line 218, in print_color print(wrap_with_color(*args, color=color)) UnicodeEncodeError: ‘ascii’ codec can’t encode character ‘\U0001f680’ in position 38: ordinal not in range(128)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File “/usr/local/bin/rasa”, line 8, in sys.exit(main()) File “/usr/local/lib/python3.6/dist-packages/rasa/main.py”, line 92, in main cmdline_arguments.func(cmdline_arguments) File “/usr/local/lib/python3.6/dist-packages/rasa/cli/x.py”, line 326, in rasa_x run_locally(args) File “/usr/local/lib/python3.6/dist-packages/rasa/cli/x.py”, line 434, in run_locally print(traceback.format_exc()) UnicodeEncodeError: ‘ascii’ codec can’t encode character ‘\U0001f680’ in position 361: ordinal not in range(128)

That’s the codepoint for the rocket emoji. I think the codec you’re using for your development environment is ASCII only so can’t handle printing non-ASCII characters. I don’t think it should affect Rasa X actually launching, but there are some troubleshooting tips in this SO question.

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