ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Bad message_filters.Subscriber callback: 'zip' object is not subscriptable

asked 2022-01-25 06:45:25 -0500

honeybunny gravatar image

Hi there,

I am having trouble with the message_filters.ApproximateTimeSynchronizer. I am working on a project where I need to process camera data and BoundingBoxes as seperate topics, but keep getting this weird error when I use the ApproximateTimeSynchronizer. Therefore I tried to set up a really simple code to test the time synchronisation, but it still fails. I don't know what's going on nor can I find useful information on the internet.

This is my code:

#!/usr/bin/env python3
#-*- coding:utf-8 -*-

import rospy
from std_msgs.msg import String, Int8

import message_filters
from message_filters import ApproximateTimeSynchronizer, Subscriber

class Example():

    def __init__(self):
        self.sub = message_filters.Subscriber('/chatter', Int8)
        self.sub2 = message_filters.Subscriber('/chatter2', Int8)
        self.ts = message_filters.ApproximateTimeSynchronizer([self.sub, self.sub2], 10, 0.3, allow_headerless=True)
        self.ts.registerCallback(self.synchron_fkt) = rospy.Publisher('/result_list', String, queue_size=10)
        rospy.loginfo("Launched node heading classification")

    def synchron_fkt(self, chatter, chatter2):     
        result = f"the numbers are {chatter} and {chatter2}"

if __name__ == '__main__':
    rospy.init_node('example', anonymous=True)
    hc = Example()

There are only random integers being published on the topics "/chatter" and "/chatter2". I can process the individual topics, when I call a individual callback function like


So the topics are live, I can subscribe to them individually, but not with message_filters.ApproximateTimeSynchronizer. Here is the error I get:

[ERROR] [1643113118.568710]: bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object at 0x7f2ae3f93f10>>
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/", line 750, in _invoke_callback
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/", line 75, in callback
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/", line 57, in signalMessage
    cb(*(msg + args))
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/", line 282, in add
    for vv in itertools.product(*[zip(*s)[0] for s in stamps]):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/", line 282, in <listcomp>
    for vv in itertools.product(*[zip(*s)[0] for s in stamps]):
TypeError: 'zip' object is not subscriptable

I am using Ubuntu 16.04 LTS and ROS Kinetic with rosversion 1.12.17 . What does this TypeError mean? Is there any other way to process two seperate topics without using this message_filters?

When I use #!/usr/bin/env python2 at the start of the script, it works fine, but I need python3 to use pytorch and other packages in my bigger project. In my bigger project I am also using the python3 path, but I get the same error like above, only with the python3 path. Does anyone have an idea?

Thank you

edit retag flag offensive close merge delete


You can not mix Python 2 and Python 3 like this.

gvdhoorn gravatar image gvdhoorn  ( 2022-01-25 07:03:22 -0500 )edit

@honeybunny, as @gvdhoorn points out you will have issues mixing Python 2 & 3. Consider upgrading to ROS Noetic to use Python3 specially if you plan to use pytorch

osilva gravatar image osilva  ( 2022-01-25 08:06:42 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2023-03-02 11:13:40 -0500

bluegiraffe-sc gravatar image

updated 2023-03-02 11:15:35 -0500

I am almost one year late but leaving my answer here hoping that it will be helpful to someone in the future.

I recently run into the same problem on an Ubuntu 18.04 LTS machine with ROS Melodic. We managed to solve the issue thanks to this closed thread in the ros_comm Github thread. The quickest fix is for you to locate the /opt/ros/kinetic/lib/python2.7/dist-packages/message_filters/ file in your system and change the problematic line as follows:

for vv in itertools.product([zip(s)[0] for s in stamps]):

for vv in itertools.product([next(iter(zip(s))) for s in stamps]):

as done in 627b5af commit to ros_comm.

edit flag offensive delete link more


Your post confuses me.

The OP is using ROS Kinetic. You are using ROS Melodic. The issue you link to was resolved by ros/ros_comm#1660, which fixes the issue in ROS Melodic (ie: the version you are using).

Could you clarify why you had to fix it again?

gvdhoorn gravatar image gvdhoorn  ( 2023-03-05 10:26:48 -0500 )edit

In rereading my response, I understand that it may be confusing and I apologize for that. The reason I ran into the error (despite the fact that I use ROS Melodic) lies in my lack of care in keeping everything up-to-date, particularly on the PC in question.

However, the specific error indicated by the op can be resolved by editing the line in question as indicated.

If you think that removing the reference to my experience makes the answer clearer, I will edit my answer. Thank you for pointing out.

bluegiraffe-sc gravatar image bluegiraffe-sc  ( 2023-03-06 02:15:53 -0500 )edit

Question Tools



Asked: 2022-01-25 06:45:25 -0500

Seen: 233 times

Last updated: Mar 02