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

AttributeError: 'String' object has no attribut 'ip'

asked 2019-04-18 05:32:07 -0500

janwens gravatar image

updated 2019-04-18 07:01:18 -0500

gvdhoorn gravatar image

I try to run the code that is listed but it gives me the attribute error. The package is called "communication" and the message file is called "ipadres.msg". The goal is that I create a subsciber to my custom message

!/usr/bin/env python

import rospy 

from std_msgs.msg import String 

from communication.msg import ipadres


def callback(data): 
        print data.ip

subscriber = rospy.Subscriber('ipadres',String,callback) 

My message file looks like this:

string ip
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-04-18 07:03:06 -0500

gvdhoorn gravatar image

updated 2019-04-18 07:03:28 -0500

My message file looks like this:

string ip

But we see this in your code:

subscriber = rospy.Subscriber('ipadres',String,callback)

The String there tells your Subscriber that it should present the message that will be given to callback as a std_msgs/String type.

And as String has no field ip, you get the error message you quote.

edit flag offensive delete link more



And a nit, but: adres -> address.

gvdhoorn gravatar image gvdhoorn  ( 2019-04-18 07:03:55 -0500 )edit

Question Tools


Asked: 2019-04-18 05:32:07 -0500

Seen: 129 times

Last updated: Apr 18 '19