How to fix rosdep ERROR: Rosdep experienced an error: 'list' object has no attribute 'encode'

Problem

While running rosdep update you get the following error:

reading in sources list data from /opt/openrobots/etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Add distro "ardent"

ERROR: Rosdep experienced an error: 'list' object has no attribute 'encode'
Please go to the rosdep page [1] and file a bug report with the stack trace below.
[1] : http://www.ros.org/wiki/rosdep

rosdep version: 0.10.30

Traceback (most recent call last):
  File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/main.py", line 126, in rosdep_main
    exit_code = _rosdep_main(args)
                ^^^^^^^^^^^^^^^^^^
  File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/main.py", line 286, in _rosdep_main
    return _no_args_handler(command, parser, options, args)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/main.py", line 294, in _no_args_handler
    return command_handlers[command](options)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/main.py", line 467, in command_update
    update_sources_list(success_handler=update_success_handler,
  File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/sources_list.py", line 438, in update_sources_list
    retval.append((rds, write_cache_file(sources_cache_dir, dist['distribution'], rosdep_data)))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/sources_list.py", line 493, in write_cache_file
    key_hash = compute_filename_hash(filename_key)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/sources_list.py", line 479, in compute_filename_hash
    sha_hash.update(filename_key.encode())
                    ^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'encode'

Solution

This issue occurs because you are using an old and outdated version of rosdep - possibly since you installed rosdep 0.10.30 from the robotpkg repository. To fix this issue, you need to upgrade rosdep to the latest version:

sudo apt install python3-rosdep

After that, check if the new version is being used. If not, you might need to uninstall the old version.

After upgrading rosdep, you can run rosdep update again, and the error should be resolved.