ros / urdf_parser_py

Standalone URDF parser for Python.
81 stars 47 forks source link

Parsing with display_urdf a URDF file with the encoding indicated in the xml header #82

Open traversaro opened 9 months ago

traversaro commented 9 months ago

Passing a urdf file that starts with <?xml version='1.0' encoding='UTF-8'?> to display_urdf fails with a error.

Reproduction script using mamba

mamba create -n urdfdom-py urdfdom-py
mamba activate urdfdom-py
wget https://raw.githubusercontent.com/icub-tech-iit/ergocub-gazebo-simulations/1179630a88541479df51ebb108a21865ea251302/models/stickBot/model.urdf
$CONDA_PREFIX/lib/urdfdom_py/display_urdf model.urdf

fails with:

Traceback (most recent call last):
  File "/home/traversaro/miniforge3/envs/urdfdom-py/lib/urdfdom_py/display_urdf", line 33, in <module>
    sys.exit(load_entry_point('urdfdom-py==1.2.1', 'console_scripts', 'display_urdf')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/traversaro/miniforge3/envs/urdfdom-py/lib/python3.12/site-packages/urdf_parser_py/display_urdf.py", line 15, in main
    robot = URDF.from_xml_string(args.file.read())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/traversaro/miniforge3/envs/urdfdom-py/lib/python3.12/site-packages/urdf_parser_py/xml_reflection/core.py", line 610, in from_xml_string
    node = etree.fromstring(xml_string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "src/lxml/etree.pyx", line 3257, in lxml.etree.fromstring
  File "src/lxml/parser.pxi", line 1911, in lxml.etree._parseMemoryDocument
ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.

mamba list:

(urdfdom-py) traversaro@IITICUBLAP257:~$ mamba list
# packages in environment at /home/traversaro/miniforge3/envs/urdfdom-py:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
bzip2                     1.0.8                hd590300_5    conda-forge
ca-certificates           2023.7.22            hbcca054_0    conda-forge
icu                       73.2                 h59595ed_0    conda-forge
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
libexpat                  2.5.0                hcb278e6_1    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 13.2.0               h807b86a_2    conda-forge
libgomp                   13.2.0               h807b86a_2    conda-forge
libiconv                  1.17                 h166bdaf_0    conda-forge
libnsl                    2.0.1                hd590300_0    conda-forge
libsqlite                 3.44.0               h2797004_0    conda-forge
libstdcxx-ng              13.2.0               h7e041cc_2    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libxml2                   2.11.5               h232c23b_1    conda-forge
libxslt                   1.1.37               h0054252_1    conda-forge
libzlib                   1.2.13               hd590300_5    conda-forge
lxml                      4.9.3           py312he528aba_1    conda-forge
ncurses                   6.4                  h59595ed_2    conda-forge
openssl                   3.1.4                hd590300_0    conda-forge
pip                       23.3.1             pyhd8ed1ab_0    conda-forge
python                    3.12.0          hab00c5b_0_cpython    conda-forge
python_abi                3.12                    4_cp312    conda-forge
pyyaml                    6.0.1           py312h98912ed_1    conda-forge
readline                  8.2                  h8228510_1    conda-forge
setuptools                68.2.2             pyhd8ed1ab_0    conda-forge
tk                        8.6.13          noxft_h4845f30_101    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
urdfdom-py                1.2.1           py312h7900ff3_3    conda-forge
wheel                     0.41.3             pyhd8ed1ab_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
yaml                      0.2.5                h7f98852_2    conda-forge

Downstream issue: https://github.com/icub-tech-iit/ergocub-gazebo-simulations/issues/49 .

traversaro commented 9 months ago

As an additional detail from https://github.com/icub-tech-iit/ergocub-gazebo-simulations/issues/49, it turns out that the encoding='UTF-8' is added by the URDF export code of urdfpy/urchin in https://github.com/fishbotics/urchin/blob/5a8068a9c6f4c0d43a57d6bdb4c9be52d9fd0549/urchin/urdf.py#L3714 .

clalancette commented 9 months ago

See #83, which should fix this.