This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ServerProxy returns bad XML
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.1
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: beaumartinez, georg.brandl
Priority: normal Keywords:

Created on 2011-01-19 18:19 by beaumartinez, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
serverproxy_test.py beaumartinez, 2011-01-19 18:19 Test code that illustrates the bug; should throw xml.parsers.expat.ExpatError
Messages (5)
msg126552 - (view) Author: Beau (beaumartinez) Date: 2011-01-19 18:19
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: <?xml version=\"1.0\" encoding=\"utf-8\"?>.)

I'm running "Python 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64 bit (AMD64)] on win32".
msg126565 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-01-19 20:41
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})
msg126566 - (view) Author: Beau (beaumartinez) Date: 2011-01-19 21:03
Thanks for your time, georg.brandl. I'll file a bug report with them.
msg126567 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-01-19 21:27
BTW, you might want to exchange your API key since this one is now publicly available forever :)
msg126575 - (view) Author: Beau (beaumartinez) Date: 2011-01-19 23:50
Use my API key? That would have been telling! Fortunately I used the example API key Last.fm provide on the page I linked ;)
History
Date User Action Args
2022-04-11 14:57:11adminsetgithub: 55159
2011-01-19 23:50:37beaumartinezsetmessages: + msg126575
2011-01-19 21:27:30georg.brandlsetmessages: + msg126567
2011-01-19 21:03:06beaumartinezsetmessages: + msg126566
2011-01-19 20:41:18georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg126565

resolution: not a bug
2011-01-19 20:11:17beaumartinezsettype: compile error -> behavior
2011-01-19 18:19:02beaumartinezcreate