简体   繁体   English

Python输入干扰SimpleXMLRPCServer

[英]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. 我的假设是服务器端input的消耗正在破坏POST XML-RPC的优势。

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. 我不想不必为两个客户端和一个服务器编写某种方法,就像有点简单的1:1设置。

Really, I'm open to any alternate (python) solution. 确实,我愿意接受任何其他(python)解决方案。

You are using input() where you ought to use raw_input() . 您在应使用raw_input()地方使用input() raw_input() Try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM