问题描述:
使用gazebo的spawn_model时,模型文件没有任何问题,却报出以下错误
Traceback (most recent call last):
File "/opt/ros/melodic/lib/gazebo_ros/spawn_model", line 239, in <module>
exit_code = sm.run()
File "/opt/ros/melodic/lib/gazebo_ros/spawn_model", line 149, in run
xml_parsed = xml.etree.ElementTree.fromstring(model_xml)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1311, in XML
parser.feed(text)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1657, in feed
self._parser.Parse(data, 0)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u5b8f' in position 466: ordinal not in range(128)
[ INFO] [1629556008.000224497, 0.025000000]: Physics dynamic reconfigure ready.
[spawn_model-4] process has died [pid 3747, exit code 1, cmd /opt/ros/melodic/lib/gazebo_ros/spawn_model -urdf -model mycar -param robot_description __name:=spawn_model __log:=/home/lzm/.ros/log/d0a67326-028b-11ec-8dee-3cf011fb4fa5/spawn_model-4.log].
log file: /home/lzm/.ros/log/d0a67326-028b-11ec-8dee-3cf011fb4fa5/spawn_model-4*.log
解决方案:
可以看到还是编码老问题,找到上面出现的/usr/lib/python2.7/xml/etree/ElementTree.py文件,用我之前博客的方法,加入以下代码
之前博客的解决方法
reload(sys)
sys.setdefaultencoding("utf-8")
|