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

How to get the publisher name from a received message in rospy?

asked 2011-06-21 07:03:52 -0500

pparescasellas gravatar image

Hey everybody,

I can't find anywhere how to get the publisher name from a received message using python. In C++ I just have to do the following:

callback( const ros::MessageEvent< cola2_common::BhResponse const >& event )
    const std::string& publisher_name = event.getPublisherName() ;

What's the equivalent in python? Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2011-06-21 07:12:47 -0500

bhaskara gravatar image

updated 2017-08-02 15:08:54 -0500

gvdhoorn gravatar image

See here:

Edit (by @jayess ):

Just so you don't have to go clicking around for the answer (from @bhaskara's link):

A subscriber can get access to a "connection header", which includes debugging information such as who sent the message, as well information like whether or not a message was latched. This data is stored as the _connection_header field of a received message.


print m._connection_header
{'callerid': '/talker_38321_1284999593611',
 'latching': '0',
 'md5sum': '992ce8a1687cec8c8bd883ec73ca41d1',
 'message_definition': 'string data\n\n',
 'topic': '/chatter',
 'type': 'std_msgs/String'}

We do not recommend using callerid information beyond debugging purposes, as it can lead to brittle code in an anonymous publish/subscribe architecture.

edit flag offensive delete link more


@jayess: I've merged your additional answer with the one by @bhaskara.

gvdhoorn gravatar image gvdhoorn  ( 2017-08-02 15:09:28 -0500 )edit

@gvdhoorn, great. Even better than two answers.

jayess gravatar image jayess  ( 2017-08-02 15:53:06 -0500 )edit

Question Tools


Asked: 2011-06-21 07:03:52 -0500

Seen: 2,117 times

Last updated: Aug 02 '17