Luís Ramalho
Luís Ramalho

Reputation: 10208

Ruby 2.0p0 and XMLRPC::Client

I am experiencing issues with Ruby 2.0p0 and XMLRPC::Client. When I run the code below in 2 different versions of ruby, I get a correct response on 1.9.3 but an error with 2.0.0. Anyone with the same issues? Is the solution just not to use the newest version of ruby or is there a workaround?

require "xmlrpc/client"

server = XMLRPC::Client.new2('http://api.flickr.com/services/xmlrpc/')
begin
  res = server.call('flickr.test.echo')
  puts res
rescue XMLRPC::FaultException => e
  puts e.faultCode
  puts e.faultString
end

Using ruby-1.9.3-p392 [ x86_64 ]

I get the correct response from flickr, since I didn't supply an API key:

100
Invalid API Key (Key has invalid format)

Using ruby-2.0.0-p0 [ x86_64 ]

I get an error from ruby saying "Wrong size. Was 365, should be 207 (RuntimeError)"

/home/luisramalho/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/xmlrpc/client.rb:506:in `do_rpc': Wrong size. Was 365, should be 207 (RuntimeError)
    from /home/luisramalho/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/xmlrpc/client.rb:281:in `call2'
    from /home/luisramalho/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/xmlrpc/client.rb:262:in `call'
    from xmlrpc.rb:5:in `<main>'

Upvotes: 3

Views: 1073

Answers (2)

duncan
duncan

Reputation: 6283

I proposed a patch for this. Lets see what the team thinks about it.

https://github.com/ruby/ruby/pull/308

Upvotes: 2

Ken Mazaika
Ken Mazaika

Reputation: 1142

I had a similar problem accessing a different xml rpc api (upcdatabase.com's) (seriously, who still uses xml rpc apis?) with ruby2.

My solution was to use a different xmlrpc library than ruby's default. LibXML-XMLRPC. It uses c extentions and is supposed to be faster than the standard library one, but it was last updated in 2008, so who knows how true that statement is today.

This is what my code ended up being that worked.

require 'xml/libxml/xmlrpc'
require 'net/http'
net = Net::HTTP.new("www.upcdatabase.com", 80)

server = XML::XMLRPC::Client.new(net, "/xmlrpc")
result = server.call('lookup', 'rpc_key' => "YOLOSWAG", 'upc' => "071160055506")

Hope this helps.

Upvotes: 3

Related Questions