Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UnicodeEncodeError #578

Closed
wants to merge 1 commit into from
Closed

Fix UnicodeEncodeError #578

wants to merge 1 commit into from

Conversation

yukota
Copy link

@yukota yukota commented Jan 9, 2014

if fail to encode to utf8, unencoded charactor is written.

if fail to encode to utf8, unencoded charactor is written.
@dirk-thomas
Copy link
Member

Can you please provide a reproducible example which shows when this patch is needed?

@yukota
Copy link
Author

yukota commented Jan 9, 2014

This code throw UnicodeEncodeError in out.write(jp)
Same problem is occurred
.

# -*- coding: utf-8 -*-
from cStringIO import StringIO
out = StringIO()
out.write("test\n")
jp="#ああああ"
try:
        jp=jp.encode('utf8')
except UnicodeDecodeError:
        pass
jp=jp.decode('utf8','replace')
out.write(jp)
print (out.getvalue())

@dirk-thomas
Copy link
Member

I tried to reproduce your problem with a simple package which outputs unicode characters. You can find the test repo at https://github.com/dirk-thomas/catkin_test_unicode

But when invoking CMake on it the output is perfectly fine:

-- +++ processing catkin package: 'foo'
-- ==> add_subdirectory(foo)
#ああああ
-- Configuring done

Can you please provide a complete example with a catkin package where you have the problem?

@yukota
Copy link
Author

yukota commented Jan 10, 2014

I execute "./src/catkin/bin/catkin_make_isolated --install".
Trace is below.

Base path: /home/yukota/ros_catkin_ws
Source space: /home/yukota/ros_catkin_ws/src
Build space: /home/yukota/ros_catkin_ws/build_isolated
Devel space: /home/yukota/ros_catkin_ws/devel_isolated
Install space: /home/yukota/ros_catkin_ws/install_isolated
------------------------------------------------------------------------------------
~~  traversing 250 packages in topological order:
~~  - catkin
~~  - genmsg
~~  - gencpp
~~  - genlisp
~~  - genpy
~~  - angles
~~  - bfl (plain cmake)
~~  - bond_core
~~  - camera_calibration
~~  - cmake_modules
~~  - common_msgs
~~  - common_tutorials
~~  - console_bridge (plain cmake)
~~  - class_loader
~~  - cpp_common
~~  - desktop
~~  - desktop_full
~~  - diagnostics
~~  - driver_common
~~  - eigen_stl_containers
~~  - executive_smach
~~  - gazebo_ros_pkgs
~~  - geometry
~~  - geometry_experimental
~~  - geometry_tutorials
~~  - image_common
~~  - image_pipeline
~~  - image_transport_plugins
~~  - laser_pipeline
~~  - media_export
~~  - message_generation
~~  - message_runtime
~~  - mk
~~  - mobile
~~  - navigation
~~  - nodelet_core
~~  - octomap (plain cmake)
~~  - opencv2 (plain cmake)
~~  - openslam_gmapping
~~  - orocos_kdl (plain cmake)
~~  - perception
~~  - perception_pcl
~~  - python_orocos_kdl (plain cmake)
~~  - qt_dotgraph
~~  - qt_gui
~~  - qt_gui_app
~~  - qt_gui_core
~~  - qt_gui_py_common
~~  - random_numbers
~~  - robot
~~  - robot_model
~~  - ros
~~  - ros_base
~~  - ros_comm
~~  - ros_full
~~  - ros_tutorials
~~  - rosbag_migration_rule
~~  - rosbash
~~  - rosboost_cfg
~~  - rosbuild
~~  - rosclean
~~  - roscpp_traits
~~  - roscreate
~~  - rosdoc_lite
~~  - rosgraph
~~  - roslang
~~  - roslaunch
~~  - roslisp
~~  - rosmake
~~  - rosmaster
~~  - rosmsg
~~  - rospack
~~  - roslib
~~  - rosparam
~~  - rospy
~~  - rosservice
~~  - rostime
~~  - roscpp_serialization
~~  - python_qt_binding
~~  - rosbag_storage
~~  - rosunit
~~  - rosconsole
~~  - pluginlib
~~  - qt_gui_cpp
~~  - resource_retriever
~~  - rosconsole_bridge
~~  - rostest
~~  - rqt_action
~~  - rqt_bag
~~  - rqt_bag_plugins
~~  - rqt_common_plugins
~~  - rqt_console
~~  - rqt_dep
~~  - rqt_graph
~~  - rqt_gui
~~  - rqt_logger_level
~~  - rqt_moveit
~~  - rqt_msg
~~  - rqt_nav_view
~~  - rqt_plot
~~  - rqt_pose_view
~~  - rqt_publisher
~~  - rqt_py_common
~~  - rqt_py_console
~~  - rqt_reconfigure
~~  - rqt_robot_dashboard
~~  - rqt_robot_monitor
~~  - rqt_robot_plugins
~~  - rqt_robot_steering
~~  - rqt_runtime_monitor
~~  - rqt_service_caller
~~  - rqt_shell
~~  - rqt_srv
~~  - rqt_tf_tree
~~  - rqt_top
~~  - rqt_topic
~~  - rqt_web
~~  - simulators
~~  - smach
~~  - smach_ros
~~  - smclib
~~  - stage (plain cmake)
~~  - std_msgs
~~  - actionlib_msgs
~~  - bond
~~  - diagnostic_msgs
~~  - geometry_msgs
~~  - eigen_conversions
~~  - kdl_conversions
~~  - nav_msgs
~~  - rosgraph_msgs
~~  - sensor_msgs
~~  - camera_calibration_parsers
~~  - cv_bridge
~~  - image_geometry
~~  - map_msgs
~~  - pcl_msgs
~~  - shape_msgs
~~  - smach_msgs
~~  - std_srvs
~~  - stereo_msgs
~~  - tf2_msgs
~~  - tf2
~~  - tf2_bullet
~~  - trajectory_msgs
~~  - control_msgs
~~  - gazebo_msgs
~~  - urdfdom_headers (plain cmake)
~~  - urdf_parser_plugin
~~  - urdfdom (plain cmake)
~~  - vision_opencv
~~  - visualization_msgs
~~  - shape_tools
~~  - geometric_shapes
~~  - visualization_tutorials
~~  - viz
~~  - xacro
~~  - xmlrpcpp
~~  - roscpp
~~  - bondcpp
~~  - bondpy
~~  - collada_parser
~~  - diagnostic_common_diagnostics
~~  - dynamic_reconfigure
~~  - joint_state_publisher
~~  - move_base_msgs
~~  - nodelet
~~  - nodelet_tutorial_math
~~  - pcl_conversions
~~  - pluginlib_tutorials
~~  - roscpp_tutorials
~~  - rosout
~~  - actionlib
~~  - actionlib_tutorials
~~  - diagnostic_aggregator
~~  - diagnostic_updater
~~  - filters
~~  - message_filters
~~  - image_transport
~~  - camera_info_manager
~~  - image_view
~~  - polled_camera
~~  - rosnode
~~  - rospy_tutorials
~~  - rostopic
~~  - roswtf
~~  - rqt_gui_cpp
~~  - rqt_gui_py
~~  - rqt_image_view
~~  - self_test
~~  - tf2_py
~~  - tf2_ros
~~  - tf
~~  - tf2_geometry_msgs
~~  - tf2_kdl
~~  - tf2_tools
~~  - timestamp_tools
~~  - topic_tools
~~  - rosbag
~~  - amcl
~~  - compressed_depth_image_transport
~~  - compressed_image_transport
~~  - diagnostic_analysis
~~  - driver_base
~~  - fake_localization
~~  - gmapping
~~  - image_proc
~~  - image_rotate
~~  - interactive_markers
~~  - interactive_marker_tutorials
~~  - laser_geometry
~~  - laser_assembler
~~  - map_server
~~  - nodelet_topic_tools
~~  - pcl_ros
~~  - depth_image_proc
~~  - laser_filters
~~  - robot_pose_ekf
~~  - rqt_launch
~~  - stage_ros
~~  - stereo_image_proc
~~  - tf_conversions
~~  - theora_image_transport
~~  - turtlesim
~~  - turtle_actionlib
~~  - turtle_tf
~~  - urdf
~~  - collada_urdf
~~  - gazebo_plugins
~~  - gazebo_ros
~~  - kdl_parser
~~  - robot_state_publisher
~~  - rviz
~~  - librviz_tutorial
~~  - rqt_rviz
~~  - rviz_plugin_tutorials
~~  - rviz_python_tutorial
~~  - urdf_tutorial
~~  - visualization_marker_tutorials
~~  - voxel_grid
~~  - costmap_2d
~~  - nav_core
~~  - base_local_planner
~~  - carrot_planner
~~  - clear_costmap_recovery
~~  - dwa_local_planner
~~  - move_slow_and_clear
~~  - navfn
~~  - rotate_recovery
~~  - move_base
------------------------------------------------------------------------------------
==> Processing catkin package: 'catkin'
Makefile exists, skipping explicit cmake invocation...
==> make cmake_check_build_system in '/home/yukota/ros_catkin_ws/build_isolated/catkin'
==> make -j1 -l1 in '/home/yukota/ros_catkin_ws/build_isolated/catkin'
Unhandled exception of type 'UnicodeEncodeError':
Traceback (most recent call last):
  File "./src/catkin/bin/../python/catkin/builder.py", line 832, in build_workspace_isolated
    number=index + 1, of=len(ordered_packages)
  File "./src/catkin/bin/../python/catkin/builder.py", line 585, in build_package
    destdir=destdir
  File "./src/catkin/bin/../python/catkin/builder.py", line 378, in build_catkin_package
    if has_make_target(build_dir, 'install'):
  File "./src/catkin/bin/../python/catkin/builder.py", line 389, in has_make_target
    output = run_command(['make', '-pn'], path, quiet=True)
  File "./src/catkin/bin/../python/catkin/builder.py", line 208, in run_command
    out.write(line)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 2-15: ordinal not in range(128)
<== Failed to process package 'catkin': 
  'ascii' codec can't encode characters in position 2-15: ordinal not in range(128)
Command failed, exiting.


I add print like below in run_command

    out = StringIO() if quiet else sys.stdout
    if capture:
        print(cmd)
        while True:
            line = proc.stdout.readline()
            print(line)
            try:
                # in case the input is already unicode
                line = line.encode('utf8')
            except (AttributeError, UnicodeDecodeError):
                pass
            line = line.decode('utf8', 'replace')

Result is below

==> Processing catkin package: 'catkin'
Makefile exists, skipping explicit cmake invocation...
==> make cmake_check_build_system in '/home/yukota/ros_catkin_ws/build_isolated/catkin'
['make', 'cmake_check_build_system']

==> make -j1 -l1 in '/home/yukota/ros_catkin_ws/build_isolated/catkin'
['make', '-pn']
# GNU Make 3.81

# Copyright (C) 2006  Free Software Foundation, Inc.

# これはフリーソフトウェアです. 利用許諾についてはソースを

Unhandled exception of type 'UnicodeEncodeError':
Traceback (most recent call last):
  File "./src/catkin/bin/../python/catkin/builder.py", line 834, in build_workspace_isolated

My OS is Xubuntu13.10.
And lang is set Japanese.

@dirk-thomas
Copy link
Member

When setting:

export LANG=ja_JP.UTF-8

I can reproduce it with even with catkin_make and my example package.

@dirk-thomas
Copy link
Member

Since your patch would fail with Python 3 I have created a modified version of it on the unicode branch (https://github.com/ros/catkin/tree/unicode). Can you please verify that this works for you too?

I am not yet sure if that is the best way to address it but we will see...

@yukota
Copy link
Author

yukota commented Jan 11, 2014

I checked your fix.
But not fixed.

==> Processing catkin package: 'catkin'
Makefile exists, skipping explicit cmake invocation...
==> make cmake_check_build_system in '/home/yukota/ros_catkin_ws/build_isolated/catkin'
==> make -j1 -l1 in '/home/yukota/ros_catkin_ws/build_isolated/catkin'
Unhandled exception of type 'UnicodeEncodeError':
Traceback (most recent call last):
  File "./src/catkin/bin/../python/catkin/builder.py", line 834, in build_workspace_isolated
    number=index + 1, of=len(ordered_packages)
  File "./src/catkin/bin/../python/catkin/builder.py", line 587, in build_package
    destdir=destdir
  File "./src/catkin/bin/../python/catkin/builder.py", line 380, in build_catkin_package
    if has_make_target(build_dir, 'install'):
  File "./src/catkin/bin/../python/catkin/builder.py", line 391, in has_make_target
    output = run_command(['make', '-pn'], path, quiet=True)
  File "./src/catkin/bin/../python/catkin/builder.py", line 210, in run_command
    out.write(line)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 2-15: ordinal not in range(128)
<== Failed to process package 'catkin': 
  'ascii' codec can't encode characters in position 2-15: ordinal not in range(128)
Command failed, exiting.

@dirk-thomas
Copy link
Member

I tried several more variants but could not find any approach which worked with Python 3 and japanese LANG set. Until a patch supports both Python 2 and 3 I can't merge it.

@wjwwood Any idea how the code for that should look like?

@wjwwood
Copy link
Member

wjwwood commented Jan 13, 2014

@dirk-thomas It may be a problem with linux or your version of CMake? It works perfectly fine on my machine:

william@dosa:/tmp/unicode_ws
% export LANG=ja_JP.UTF-8

william@dosa:/tmp/unicode_ws
% catkin_make --force-cmake
Base path: /tmp/unicode_ws
Source space: /tmp/unicode_ws/src
Build space: /tmp/unicode_ws/build
Devel space: /tmp/unicode_ws/devel
Install space: /tmp/unicode_ws/install
####
#### Running command: "cmake /tmp/unicode_ws/src -DCATKIN_DEVEL_PREFIX=/tmp/unicode_ws/devel -DCMAKE_INSTALL_PREFIX=/tmp/unicode_ws/install" in "/tmp/unicode_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /tmp/unicode_ws/devel
-- Using CMAKE_PREFIX_PATH: /Users/william/hydro/install
-- This workspace overlays: /Users/william/hydro/install
-- Using default Python package layout
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /tmp/unicode_ws/build/test_results
-- Found gtest: gtests will be built
-- catkin 0.5.77
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - foo
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'foo'
-- ==> add_subdirectory(catkin_test_unicode)
#ああああ
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/unicode_ws/build
####
#### Running command: "make -j4 -l4" in "/tmp/unicode_ws/build"
####

@wjwwood
Copy link
Member

wjwwood commented Jan 13, 2014

A more complete example, showing en_US and ja_JP, using the unicode branch of catkin in a clean terminal:

william@dosa:/tmp/unicode_ws
% env | grep LANG
LANG=en_US.UTF-8

william@dosa:/tmp/unicode_ws
% ./src/catkin/bin/catkin_make --force-cmake
Base path: /tmp/unicode_ws
Source space: /tmp/unicode_ws/src
Build space: /tmp/unicode_ws/build
Devel space: /tmp/unicode_ws/devel
Install space: /tmp/unicode_ws/install
####
#### Running command: "cmake /tmp/unicode_ws/src -DCATKIN_DEVEL_PREFIX=/tmp/unicode_ws/devel -DCMAKE_INSTALL_PREFIX=/tmp/unicode_ws/install" in "/tmp/unicode_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /tmp/unicode_ws/devel
-- Using CMAKE_PREFIX_PATH:
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using default Python package layout
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /tmp/unicode_ws/build/test_results
-- Found gtest: gtests will be built
-- catkin 0.5.79
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - foo
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'foo'
-- ==> add_subdirectory(catkin_test_unicode)
#ああああ
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/unicode_ws/build
####
#### Running command: "make -j4 -l4" in "/tmp/unicode_ws/build"
####

william@dosa:/tmp/unicode_ws
% export LANG=ja_JP.UTF-8

william@dosa:/tmp/unicode_ws
% env | grep LANG
LANG=ja_JP.UTF-8

william@dosa:/tmp/unicode_ws
% ./src/catkin/bin/catkin_make --force-cmake
Base path: /tmp/unicode_ws
Source space: /tmp/unicode_ws/src
Build space: /tmp/unicode_ws/build
Devel space: /tmp/unicode_ws/devel
Install space: /tmp/unicode_ws/install
####
#### Running command: "cmake /tmp/unicode_ws/src -DCATKIN_DEVEL_PREFIX=/tmp/unicode_ws/devel -DCMAKE_INSTALL_PREFIX=/tmp/unicode_ws/install" in "/tmp/unicode_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /tmp/unicode_ws/devel
-- Using CMAKE_PREFIX_PATH:
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using default Python package layout
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /tmp/unicode_ws/build/test_results
-- Found gtest: gtests will be built
-- catkin 0.5.79
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - foo
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'foo'
-- ==> add_subdirectory(catkin_test_unicode)
#ああああ
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/unicode_ws/build
####
#### Running command: "make -j4 -l4" in "/tmp/unicode_ws/build"
####

@dirk-thomas
Copy link
Member

Have you tried it with Python 3 too?

@wjwwood
Copy link
Member

wjwwood commented Jan 15, 2014

How can I tell catkin to use Python3 to invoke things?

@dirk-thomas
Copy link
Member

python3 catkin_make 😉

I think it will require catkin_pkg available to Python 3 - just add the src folder of a checkout of that repo to the Python path.

@wjwwood
Copy link
Member

wjwwood commented Jan 15, 2014

Ok, same thing as before, but invoking catkin_make with python3:

william@dosa:/tmp/unicode_ws
% env | grep LANG
LANG=en_US.UTF-8

william@dosa:/tmp/unicode_ws
% python3 ./src/catkin/bin/catkin_make --force-cmake --no-color
Base path: /tmp/unicode_ws
Source space: /tmp/unicode_ws/src
Build space: /tmp/unicode_ws/build
Devel space: /tmp/unicode_ws/devel
Install space: /tmp/unicode_ws/install
####
#### Running command: "cmake /tmp/unicode_ws/src -DCATKIN_DEVEL_PREFIX=/tmp/unicode_ws/devel -DCMAKE_INSTALL_PREFIX=/tmp/unicode_ws/install" in "/tmp/unicode_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /tmp/unicode_ws/devel
-- Using CMAKE_PREFIX_PATH:
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using default Python package layout
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /tmp/unicode_ws/build/test_results
-- Found gtest: gtests will be built
-- catkin 0.5.79
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - foo
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'foo'
-- ==> add_subdirectory(catkin_test_unicode)
#ああああ
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/unicode_ws/build
####
#### Running command: "make -j4 -l4" in "/tmp/unicode_ws/build"
####

william@dosa:/tmp/unicode_ws
% export LANG=ja_JP.UTF-8

william@dosa:/tmp/unicode_ws
% env | grep LANG
LANG=ja_JP.UTF-8

william@dosa:/tmp/unicode_ws
% python3 ./src/catkin/bin/catkin_make --force-cmake --no-color
Base path: /tmp/unicode_ws
Source space: /tmp/unicode_ws/src
Build space: /tmp/unicode_ws/build
Devel space: /tmp/unicode_ws/devel
Install space: /tmp/unicode_ws/install
####
#### Running command: "cmake /tmp/unicode_ws/src -DCATKIN_DEVEL_PREFIX=/tmp/unicode_ws/devel -DCMAKE_INSTALL_PREFIX=/tmp/unicode_ws/install" in "/tmp/unicode_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /tmp/unicode_ws/devel
-- Using CMAKE_PREFIX_PATH:
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using default Python package layout
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /tmp/unicode_ws/build/test_results
-- Found gtest: gtests will be built
-- catkin 0.5.79
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - foo
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'foo'
-- ==> add_subdirectory(catkin_test_unicode)
#ああああ
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/unicode_ws/build
####
#### Running command: "make -j4 -l4" in "/tmp/unicode_ws/build"
####

@wjwwood
Copy link
Member

wjwwood commented Jan 15, 2014

Btw, I just did sudo pip-3.3 install catkin_pkg.

@dirk-thomas
Copy link
Member

I updated the test package a couple of times. When I invoke the following command in a workspace with catkin/unicode and catkin_test_unicode/master:

python3 ./src/catkin/bin/catkin_make --no-color -DPYTHON_VERSION=3

The output is ok with en locale. But when I switch to jp locale the output is:

PYTHON_EXECUTABLE /usr/bin/python3.2
Traceback (most recent call last):
  File "/home/dthomas/ros/hydro/unicode/src/foo/foo.py", line 4, in <module>
    print(jp)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-4: ordinal not in range(128)

@josegaert
Copy link

I have the same bug on my french Debian.

root@anoesjka:~/ros_catkin_ws# env | grep LANG
LANG=fr_BE.UTF-8
LANGUAGE=fr_BE:fr
root@anoesjka:~/ros_catkin_ws# ./src/catkin/bin/catkin_make_isolated --install --install-space /opt/ros/hydro
==&gt; Processing catkin package: 'catkin'
Makefile exists, skipping explicit cmake invocation...
==&gt; make cmake_check_build_system in '/root/ros_catkin_ws/build_isolated/catkin'
==&gt; make -j4 -l4 in '/root/ros_catkin_ws/build_isolated/catkin'
Unhandled exception of type 'UnicodeEncodeError':
Traceback (most recent call last):
  File "./src/catkin/bin/../python/catkin/builder.py", line 832, in build_workspace_isolated
    number=index + 1, of=len(ordered_packages)
  File "./src/catkin/bin/../python/catkin/builder.py", line 585, in build_package
    destdir=destdir
  File "./src/catkin/bin/../python/catkin/builder.py", line 378, in build_catkin_package
    if has_make_target(build_dir, 'install'):
  File "./src/catkin/bin/../python/catkin/builder.py", line 389, in has_make_target
    output = run_command(['make', '-pn'], path, quiet=True)
  File "./src/catkin/bin/../python/catkin/builder.py", line 208, in run_command
    out.write(line)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xc9' in position 3: ordinal not in range(128)
&lt;== Failed to process package 'catkin': 
  'ascii' codec can't encode character u'\xc9' in position 3: ordinal not in range(128)
Command failed, exiting.

Now, when I change the language to English.

root@anoesjka:~/ros_catkin_ws# export LANG=en_US.UTF-8
root@anoesjka:~/ros_catkin_ws# env | grep LANG
LANG=en_US.UTF-8
LANGUAGE=fr_BE:fr
root@anoesjka:~/ros_catkin_ws# ./src/catkin/bin/catkin_make_isolated --install --install-space /opt/ros/hydro

Then it works fine.

@josegaert
Copy link

I now just tried the patch.
Unfortunately it doesn't work and gives the exact same bug.

@wjwwood
Copy link
Member

wjwwood commented Jan 30, 2014

I'll try to look at this again today, I was unable to reproduce it on OS X before, but I may have been missing something.

@wjwwood
Copy link
Member

wjwwood commented Jan 31, 2014

I cannot reproduce this with a simple example on OS X. I did exactly this:

  • Make a workspace with:
    • catkin HEAD (7fa6069)
    • test package (wjwwood/catkin_test_unicode@cfc3d9c)
  • Run ./src/catkin/bin/catkin_make
  • Remove build and devel folder
  • Run python3 ./src/catkin/bin/catkin_make
  • Remove build and devel folder
  • Change the LANG to fr_BE.UTF-8 and repeat the above
  • Change the LANG to ja_JP.UTF-8 and repeat the above

I put the output from my tests and the files I used in the test are in this gist:

https://gist.github.com/wjwwood/6efb3ff4ab42dc6b10fb

Please try and reproduce what I've done here and see if you still get the problem. If you have the problem with my above example, then we might need to consider that this bug is realted to Linux and Python's unicode support.

@wjwwood
Copy link
Member

wjwwood commented Jan 31, 2014

Just for completeness, I also ran it with catkin_make_isolated.

@dirk-thomas
Copy link
Member

The problem is still there - we had the case before that OS X behaves differently.

@wjwwood
Copy link
Member

wjwwood commented Jan 31, 2014

So, @dirk-thomas that means you have the problem when you do exactly what I did above? The first thing I was trying to figure out is whether or not I was missing the problem because of how I was testing for it.

@dirk-thomas
Copy link
Member

I did not reproduce your exact sequence.

We tested that some time ago extensively and nothing has changed since then since we couldn't find a way to make it work with Python 2 as well as 3 with english and japanese LANG environment.

@wjwwood
Copy link
Member

wjwwood commented Jan 31, 2014

There was some confusion, you had changed your foo.py around multiple times and you had weird calls to .encode which when removed didn't produce a problem for me, that's why I redid this in a fresh example.

@wjwwood
Copy link
Member

wjwwood commented Jan 31, 2014

Which you removed here:

https://github.com/dirk-thomas/catkin_test_unicode/commit/5baa27f0e721d1d4ba1cdfb72d1ebf869fb93751

I can try to reproduce it with you current repository. But unless we have a good reason as to why it happens on Linux and not BSD (my mac) then I'm not sure we need to change how we are doing things, or at least it is not clear to me that we are addressing the correct problem.

@dirk-thomas
Copy link
Member

If you want to look into it please try it on a Ubuntu machine first with the 2x2 cases described above. That failed for me always for one of the cases - I could not come up with Python code which made all four work.

@wjwwood
Copy link
Member

wjwwood commented Jan 31, 2014

I cannot reproduce it with your repository either. I'll try to download linux later when I have better internet, but it seems to me that Linux is not handling this correctly.

@saljam
Copy link

saljam commented Feb 17, 2014

cStringIO (which is imported on python2) does not support unicode. Using vanilla StringIO fixes this for me.

Try https://github.com/saljam/catkin/commit/db1fb3451c6004e7c872db4b45be27e9b7599c3f with:

    FOO=☺ python3 ./src/catkin/bin/catkin_make

and

    FOO=☺ python2 ./src/catkin/bin/catkin_make

@dirk-thomas
Copy link
Member

I have extended the example significantly to allow a clear way to run the tests: https://github.com/dirk-thomas/catkin_test_unicode

When I run the check_all.py script on Ubuntu 12.10 I get the following results:

  • Py2 en_US passes
  • Py3 en_US passes
  • Py2 ja_JP passes
  • Py3 ja_JP configure fails with:
    • Using stdout encoding: ANSI_X3.4-1968
    • Traceback (most recent call last):
      • File ".../py3_ja_JP/src/catkin_test_unicode/foo.py", line 9, in
      • print(jp)
    • UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-4: ordinal not in range(128)

The result is the same with the current code of catkin as well as when I simplify the builder.py code (https://github.com/ros/catkin/blob/indigo-devel/python/catkin/builder.py#L193) to:

try:
    line = line.decode('utf8')
except (AttributeError, UnicodeDecodeError):
    pass
line = line.encode('utf8', 'replace')

The most likely reason why the behavior on OS X is different is a different value for the stdout encoding. @wjwwood Can you please validate that on OS X and post the summarized result?

@dirk-thomas
Copy link
Member

@saljam Changing the StringIO import in the builder script has no effect for me - since the actual problem happens inside of the invoked foo.py script and therefore even before the builder script is trying to process the output.

@saljam
Copy link

saljam commented Feb 18, 2014

Right, it sounds like your machine's Japanese locale is missing or broken (on Ubuntu the encoding should be UTF8, not ANSI_X3.4-1968). Try 'locale -a' to see what's on, and locale-gen to generate the missing ones.

On my machine, locale -a yields

    C
    C.UTF-8
    POSIX
    en_GB.utf8
    ja_JP.utf8

and foo.py passes in all 4 cases.

But that's unrelated to the StringIO issue. :) Just Python3 defaulting to ASCII when the system encoding is missing. And being strict about it.

@wjwwood
Copy link
Member

wjwwood commented Feb 18, 2014

Something I discovered during my research on missing locale's with python:

http://stackoverflow.com/questions/14547631/python-locale-error-unsupported-locale-setting

% LANG=ja_JP.UTF-8 python -c "import locale; import os; print locale.setlocale(locale.LC_ALL, os.environ.get('LANG', locale.getdefaultlocale()[0]))"
ja_JP.UTF-8

% python -c "import locale; import os; print locale.setlocale(locale.LC_ALL, os.environ.get('LANG', locale.getdefaultlocale()[0]))"
en_US.UTF-8

I expect the first line in the above snippet to fail on the machines reporting this error.

@dirk-thomas
Copy link
Member

@josegaert Can you please run locale -a and check if the locale you used before (fr_BE) is actually listed there?

@dirk-thomas
Copy link
Member

Closed in favor of #595 since this PR does not work with all combinations of Python versions and LANG values.

@josegaert
Copy link

Hey,

root@anoesjka:~# locale -a
C
C.UTF-8
fr_BE.utf8
POSIX

Greetings

@dirk-thomas
Copy link
Member

@josegaert Can you please check if PR #595 will work for you, too?

dirk-thomas added a commit that referenced this pull request Feb 23, 2014
fix unicode error with japanese LANG (fix #578)
cwecht pushed a commit to cwecht/catkin that referenced this pull request Mar 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants