Unable to run the tutorial server and client
I'm trying to follow the tutorials and I'm using ros noetic. But I'm having a problem with tutorial 16, even though I've followed the previous tutorials exactly. I get the following error when I want to run my add_two_ints_server.py and add_two_ints_client.py files. rosrun beginner_tutorials add_two_ints_server.py
Traceback (most recent call last): File "/home/name/catkin_ws/devel/lib/beginner_tutorials/add_two_ints_server.py", line 15, in <module> exec(compile(fh.read(), python_script, 'exec'), context) File "/home/name/catkin_ws/src/beginner_tutorials/scripts/add_two_ints_server.py", line 4 from __future__ import print_function ^ IndentationError: unexpected indent
this is the code that i used for server. #!/usr/bin/env pyhton
from __future__ import print_function
from beginner_tutorials.srv import AddTwoInts,AddTwoIntsResponse
import rospy
def handle_add_two_ints(req):
print("Returning [%s + %s = %s]"%(req.a, req.b, (req.a + req.b)))
return AddTwoIntsResponse(req.a + req.b)
def add_two_ints_server():
rospy.init_node('add_two_ints_server')
s = rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints)
print("Ready to add two ints.")
rospy.spin()
if __name__ == "__main__":
add_two_ints_server()
and this one is for client #!/usr/bin/env python
from __future__ import print_function
import sys
import rospy
from beginner_tutorials.srv import *
def add_two_ints_client(x, y):
rospy.wait_for_service('add_two_ints')
try:
add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts)
resp1 = add_two_ints(x, y)
return resp1.sum
except rospy.ServiceException as e:
print("Service call failed: %s"%e)
def usage():
return "%s [x y]"%sys.argv[0]
if __name__ == "__main__":
if len(sys.argv) == 3:
x = int(sys.argv[1])
y = int(sys.argv[2])
else:
print(usage())
sys.exit(1)
print("Requesting %s+%s"%(x, y))
print("%s + %s = %s"%(x, y, add_two_ints_client(x, y)))
how can i solve this problem thanks for help