Issue 10950: ServerProxy returns bad XML (original) (raw)

xmlrpc.client.ServerProxy calls that return XML (ie, the a non-marshallable type) give bad XML, with " (backslash then double quote characters, '\"'; not escaped double quote) in place of ", and ' in place of '. Ampersands aren't XML-escaped either.

(I have only tested this with Last.fm's API but I have made calls that return marshallable types with no problem, so I'm assuming the issue lies with ServerProxy and not Last.fm's XML-RPC servers.)

The following test code, identical to that in the attached file illustrates the bug; it throws an xml.parsers.expat.ExpatError as the XML is bad:

Get a Last.fm user's library.

http://www.last.fm/api/show?service=323

import xmlrpc.client import xml.etree

server = xmlrpc.client.ServerProxy('http://ws.audioscrobbler.com/2.0/') parameters = {'api_key': 'b25b959554ed76058ac220b7b2e0a026', 'user': 'joanofarctan', 'page': 1}

tracks = server.library.getTracks(parameters) tracks_xml = xml.etree.ElementTree.parse(tracks)

Should get "xml.parsers.expat.ExpatError: XML declaration not well-formed: line 1, column 14".

(Line 1, column 14 is a backslash: .)

I'm running "Python 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] on win32".

Not sure what you mean by "non-marshallable type". The Last.fm API returns the XML as an XMLRPC string, including the backslashes.

I tried the same call in Ruby using the script below, and get the backslashes too. I would say this is a fault of Last.fm's XMLRPC server.

Ruby code:

require 'xmlrpc/client' cl = XMLRPC::Client.new2 'http://ws.audioscrobbler.com/2.0/' puts cl.call('library.getTracks', {'api_key' => 'b25b959554ed76058ac220b7b2e0a026', 'user' => 'joanofarctan', 'page' => 1})