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

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

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

janwens gravatar image

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

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

rospy.init_node('odometry_publisher')

def callback(data): 
        print data.ip

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

My message file looks like this:

string ip
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

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

gvdhoorn gravatar image

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

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

Comments

1

And a nit, but: adres -> address.

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

Question Tools

Stats

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

Seen: 144 times

Last updated: Apr 18 '19