Exception XML-RPC class (Python)

0

I'm trying to create a class in XML-RPC, but it's giving an Exception, but I do not understand why. It's just a simple example:

  

server.py

from xmlrpc.server import SimpleXMLRPCServer
import pickle

class Animal:
 def __init__(self, number_of_paws, color):
   self.number_of_paws = number_of_paws
   self.color = color

class Sheep(Animal):
 def __init__(self, color):
   Animal.__init__(self, 4, color)     

def main():
  print("This is a server!")
  server = SimpleXMLRPCServer(("localhost", 8080))
  server.register_function(Animal.__init__)
  server.register_function(Sheep.__init__)
  server.serve_forever()

if __name__ == "__main__":
  main()
  

client.py

import xmlrpc.client
import time
import pickle
import server

def main():
 print("This is a client!")
 client = xmlrpc.client.ServerProxy("http://localhost:8080")
 mary = client.server.Sheep("white")
 my_pickled_mary = pickle.dumps(mary)
 dolly = pickle.loads(my_pickled_mary)
 dolly.color = "black"
 print (str.format("Dolly is {0} ", dolly.color))
 print (str.format("Mary is {0} ", mary.color))

if __name__ == "__main__":
 start = time.time()
 main()
 tempo_total = ("--- %s seconds ---" % (time.time() - start))
 print("Tempo Total: " + str(tempo_total))

The server runs normal, but when I run the client, this error occurs:

  

xmlrpc.client.Fault:: method "server.Sheep" is not supported '>

What does it mean that the method is not supported?

    
asked by anonymous 25.06.2018 / 15:52

1 answer

1

The server register_function should look like

  server.register_function(Animal, "Animal")
  server.register_function(Sheep, "Sheep")

And on the Client change line 8 so that it looks like

  with xmlrpc.client.ServerProxy("http://localhost:8080") as client:

And for a simpler example of how testing only works with

  mary = client.Sheep("white")
  my_pickled_mary = pickle.dumps(mary)
  print (str.format("Mary is {0} ", mary))

The exit was:

Mary is {'number_of_paws': 4, 'color': 'white'} 
Tempo Total: --- 0.0032961368560791016 seconds ---
    
25.06.2018 / 18:59