Question: PYTHON 3 I need assistance with making the below code work, getting same error on all of them IndexError: list index out of range Client.py

PYTHON 3

I need assistance with making the below code work, getting same error on all of them

IndexError: list index out of range

Client.py

import xmlrpc.client import sys #create localhost url. Note that sys.argv[1] returns the first argument passed using command line str1 = 'http://' + sys.argv[1] + ':' + sys.argv[2] #create server proxy s = xmlrpclib.ServerProxy(str1) #convert values of x and y to integer x,y = int(sys.argv[3]), int(sys.argv[4]) #Now call the function as per the requirement print("The supported procedures are:") print(s.help()) print(s.add(x,y)) print(s.sub(x,y)) print(s.mult(x,y)) print(s.div(x,y)) print(s.servertime())

Server.py

from xmlrpc.server import SimpleXMLRPCServer #For XML-RPC import sys #for reading arguments from time import localtime, strftime #for printing time # Create server server = SimpleXMLRPCServer((sys.argv[1], int(sys.argv[2]))) #Connect to localhost #server.register_introspection_functions() def help(): return ['servertime', 'add', 'sub', 'mult', 'div'] #return list of procedures def servertime(): return strftime("%H:%M:%S", localtime()) #return time in format. note that strftime is used to format time to H:M:S def add(x,y): return "%d + %d is %s"%(x, y, x+y)#return addition def sub(x,y): return "%d - %d is %s"%(x, y, x-y)#return subtraction def mult(x,y): return "%d * %d is %s"%(x, y, x*y) #return multiplication def div(x,y): if y != 0: return "%d / %d is %s"%(x,y,x*1.0/y) #return division if y is not 0 else: return "%d / %d is Infinity"%(x,y) #eturn infinity if y is 0 #now register all the defined procedures using server.register_function() server.register_function(help) server.register_function(add) server.register_function(servertime) server.register_function(sub) server.register_function(mult) server.register_function(div) #run a forever loop server.serve_forever()

REST.py

# importing the requests library import requests # api-endpoint URL = "http://maps.googleapis.com/maps/api/geocode/json" # location given here location = "delhi technological university" # defining a params dict for the parameters to be sent to the API PARAMS = {'address': location} # sending get request and saving the response as response object r = requests.get(url=URL, params=PARAMS) # extracting data in json format data = r.json() # extracting latitude, longitude and formatted address # of the first matching location latitude = data['results'][0]['geometry']['location']['lat'] longitude = data['results'][0]['geometry']['location']['lng'] formatted_address = data['results'][0]['formatted_address'] # printing the output print("Latitude:%s Longitude:%s Formatted Address:%s" % (latitude, longitude, formatted_address))

Need them as soon as posssible

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!