ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

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 -0500

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/catkin.py", line 272, in main
    catkin_main(sysargs)
  File "/usr/lib/python2.7/dist-packages/catkin_tools/commands/catkin.py", line 267, in catkin_main
    sys.exit(args.main(args) or 0)
  File "/usr/lib/python2.7/dist-packages/catkin_tools/verbs/catkin_build/cli.py", 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/build.py", 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/packages.py", 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/packages.py", line 148, in find_packages_allowing_duplicates
    xml, filename=filename, warnings=warnings)
  File "/usr/lib/python2.7/dist-packages/catkin_pkg/package.py", 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
1

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

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 charbase.com/00a7-unicode-section-sign.

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

edit flag offensive delete link more

Comments

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

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

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

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

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
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.

edit flag offensive delete link more

Comments

No, you don't want to do this. See https://stackoverflow.com/questions/3...

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

Question Tools

1 follower

Stats

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

Seen: 1,004 times

Last updated: Sep 07 '21