pythonsimplexmlrpcserver

Python input interfering with SimpleXMLRPCServer


I have a server along these lines:

from SimpleXMLRPCServer import SimpleXMLRPCServer
def ack(msg):
    return input("Allow? ").lower() in ['y', 'yes']
server = SimpleXMLRPCServer(("localhost", 8080))
server.register_function(ack, "ack")
server.serve_forever()

And a client along these lines:

import xmlrpclib
proxy = xmlrpclib.ServerProxy("http://localhost:8080")

with open(myfile) as mfd:
    for line in mfd.readlines():
        if proxy.ack(line):
            print line

This results in a fault being sent to the client. The fault code & string are:

1
<type 'exceptions.NameError'>:name 'y' is not defined

My assumption is the consumption of input over on the server side is killing the POST XML-RPC goodness.

I'd prefer not to have to code up some method with two clients and a server—I kind of like the simple 1:1 setup I have going.

Really, I'm open to any alternate (python) solution.


Solution

  • You are using input() where you ought to use raw_input(). Try this:

    return raw_input("Allow? ").lower() in ['y', 'yes']