Accessing Ruby objects using Python via XML-RPC?

I am trying to export a Ruby structure through XML-RPC. However, I am having some problems trying to call a method from a class that was not added directly as a handler to the XML-RPC server. See my example below:

I have a test Ruby XML-RPC server as follows:

require "xmlrpc/server"

class ExampleBar
  def bar()
    return "hello world!"
  end
end

class ExampleFoo
  def foo()
    return ExampleBar.new
  end

  def test()
    return "test!"
  end
end

s = XMLRPC::Server.new( 9090 )

s.add_introspection

s.add_handler( "example", ExampleFoo.new )

s.serve

And I have a Python XML-RPC test client as follows:

import xmlrpclib

s = xmlrpclib.Server( "http://127.0.0.1:9090/" )

print s.example.foo().bar()

I would expect the python client to print “hello world!”. as this is the equivalent of the following ruby ​​code:

example = ExampleFoo.new
puts example.foo().bar()

However, it generates an error: "xmlrpclib.ProtocolError: <ProtocolError for 127.0.0.1:9090/: 500 Internal Server Error>".

print s.example.test () is working fine.

, ExampleBar , , "" , bar() .

XML-RPC ?

, , ; , XML-RPC, ?

+3
3

Python) ServerProxy. boolean, integers, floats, , , .

, , ServerProxy, . , Ruby, , , ..

, , :

def foobar()
  return ExampleFoo.new().foo().bar()
end
+5

XML-RPC . ( jakber).

+1

Returning zero inside a supported data structure will also throw an Internal Server error message. The stdlib ruby ​​xmlrpc server does not seem to support the xmlrpc extensions that allow nils, even though the python side does this. xmlrpc4r supports nils, but I have not tried it yet.

+1
source

Source: https://habr.com/ru/post/1699146/


All Articles