Skip to content

backports.xmlrpc.server's SimpleXMLRPCServer causes a bad xml string #585

@Amir-Hadadi

Description

@Amir-Hadadi

Hi all,
After seeing the absence of SimpleXMLRPCServer from xmlrpc.server, I decided to use the given future.backports.xmlrpc.server.

One big change from the 2.x version is encoding the xml response, creating a newbytes (from SimpleXMLRPCDispatcher's _marshaled_dispatch):
return response.encode(self.encoding)
This encoding - creation of a newbytes object, wasn't there in 2.7, making me believe the new version wants to send encoded bytes instead of strings over the network, but later, when the data is written using SimpleXMLRPCRequestHandler's do_POST:
self.wfile.write(response)
What actually happens there is socket.py doing str() on the newbytes object, creating a string containing the b prefix: "b\'<xml...>'"
(note, it's not b"<xml...>", the b is actually in the string)

This string isn't read well later by xmlrpc.client.ProxyServer, which uses a parser that says this is an invalid xml string.

Here's a super simple project I made that showcases the problem, with a 2.x vs futurized code
https://github.com/Amir-Hadadi/xmlrpc-future-test

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions