AttributeError: type object 'type' has no attribute '_TYPE_SUPPORT' This might be a ROS 1 message type but it should be a ROS 2 message type. Make sure to source your ROS2 workspace after your ROS 1 workspace

I am getting an error after following along with the notes in Unit 4 ROS2 Services, section 4.4 Create a service client.

I have followed along exactly as noted in the course and checked that all of the code I entered matched the example code.

Does anyone know the cause of this error?

user:~/ros2_ws$ ros2 launch client_pkg server_client_launch_file.launch.py
[INFO] [launch]: All log files can be found below /home/user/.ros/log/2022-02-12-17-15-50-238204-3_xterm-13818
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [server_client-1]: process started with pid [13820]
[server_client-1] Traceback (most recent call last):
[server_client-1] File “/home/user/ros2_ws/install/client_pkg/lib/client_pkg/server_client”, line 11, in
[server_client-1] load_entry_point(‘client-pkg==0.0.0’, ‘console_scripts’, ‘server_client’)()
[server_client-1] File “/home/user/ros2_ws/install/client_pkg/lib/python3.8/site-packages/client_pkg/server_client.py”, line 37, in main
[server_client-1] client = ClientAsync()
[server_client-1] File “/home/user/ros2_ws/install/client_pkg/lib/python3.8/site-packages/client_pkg/server_client.py”, line 17, in init
[server_client-1] self.client = self.create_client(Empty, ‘moving’)
[server_client-1] File “/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py”, line 1248, in create_client
[server_client-1] check_for_type_support(srv_type)
[server_client-1] File “/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py”, line 20, in check_for_type_support
[server_client-1] ts = msg_type.class._TYPE_SUPPORT
[server_client-1] AttributeError: type object ‘type’ has no attribute ‘_TYPE_SUPPORT’ This might be a ROS 1 message type but it should be a ROS 2 message type. Make sure to source your ROS2 workspace after your ROS 1 workspace.
[ERROR] [server_client-1]: process has died [pid 13820, exit code 1, cmd ‘/home/user/ros2_ws/install/client_pkg/lib/client_pkg/server_client --ros-args’].

This looks like a mixup in sourcing. Are you running the ros1_bridge anywhere here? I’m asking because that could explain why it is looking for something in ROS1.

You can try launching your file in a new terminal and be sure of only sourcing ROS2 and your workspace:

source /opt/ros/foxy/setup.bash
source ~/ros2_ws/install/setup.bash