ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

catkin build -- UnicodeEncodeError: 'ascii' codec can't encode character u'\xa7' in position 5: ordinal not in range(128)

asked 2020-05-07 09:44:26 -0600

magnus gravatar image

Worked on Gazebo plugins when suddenly I could no longer build my catkin workspace. I would appreciate any advice and help you can give to help me with this. The error is:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa7' in position 5: ordinal not in range(128)

The full error output below:

magnus@magnus-vm:~/catkin_ws$ catkin build                                                        
Profile:                     default                                                                     
Extending:             [env] /opt/ros/melodic:/home/magnus/catkin_ws/devel
Workspace:                   /home/magnus/catkin_ws
Build Space:        [exists] /home/magnus/catkin_ws/build
Devel Space:        [exists] /home/magnus/catkin_ws/devel
Install Space:      [unused] /home/magnus/catkin_ws/install
Log Space:         [missing] /home/magnus/catkin_ws/logs
Source Space:       [exists] /home/magnus/catkin_ws/src
DESTDIR:            [unused] None
Devel Space Layout:          linked
Install Space Layout:        None
Additional CMake Args:       None
Additional Make Args:        None
Additional catkin Make Args: None
Internal Make Job Server:    True
Cache Job Environments:      False
Whitelisted Packages:        None
Blacklisted Packages:        None
Workspace configuration appears valid.

Traceback (most recent call last):
  File "/usr/bin/catkin", line 11, in <module>
    load_entry_point('catkin-tools==0.4.5', 'console_scripts', 'catkin')()
  File "/usr/lib/python2.7/dist-packages/catkin_tools/commands/", line 272, in main
  File "/usr/lib/python2.7/dist-packages/catkin_tools/commands/", line 267, in catkin_main
    sys.exit(args.main(args) or 0)
  File "/usr/lib/python2.7/dist-packages/catkin_tools/verbs/catkin_build/", line 422, in main
    summarize_build=opts.summarize  # Can be True, False, or None
  File "/usr/lib/python2.7/dist-packages/catkin_tools/verbs/catkin_build/", line 283, in build_isolated_workspace
    workspace_packages = find_packages(context.source_space_abs, exclude_subspaces=True, warnings=[])
  File "/usr/lib/python2.7/dist-packages/catkin_pkg/", line 87, in find_packages
    packages = find_packages_allowing_duplicates(basepath, exclude_paths=exclude_paths, exclude_subspaces=exclude_subspaces, warnings=warnings)
  File "/usr/lib/python2.7/dist-packages/catkin_pkg/", line 148, in find_packages_allowing_duplicates
    xml, filename=filename, warnings=warnings)
  File "/usr/lib/python2.7/dist-packages/catkin_pkg/", line 710, in parse_package_string
    export.attributes[str(key)] = str(value)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa7' in position 5: ordinal not in range(128)

If I can provide any further detail, let me know! Thank you in advance!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2020-05-08 03:00:15 -0600

gvdhoorn gravatar image

It's likely you have a unicode character in the package manifest which trips things up.

0xA7 is a SECTION SIGN (or: §) according to

You'll have to check your package.xml to see where that character is and remove it.

edit flag offensive delete link more


Thank you, that solved my issue. I found the § character and removed it

magnus gravatar image magnus  ( 2020-05-08 03:21:31 -0600 )edit

answered 2021-09-07 01:04:11 -0600

updated 2021-09-07 02:41:04 -0600

gvdhoorn gravatar image

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

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:,


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

edit flag offensive delete link more


No, you don't want to do this. See

gvdhoorn gravatar image gvdhoorn  ( 2021-09-07 02:41:14 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-05-07 09:44:26 -0600

Seen: 692 times

Last updated: Sep 07 '21