我从python网站上获得了XMLRPC服务器/客户端。当我运行诸如pow()之类的简单方法,从Windows添加(),div()时,客户端会正确地获取结果。但是,当我运行brocade(),它使用python模块(PyCrypto,Paramiko)从Brocade交换机获取配置信息,并返回字符串输出作为返回值,这需要2-3秒钟的时间(可能需要更长的时间,具体取决于开关命令)。我观察到服务器正确执行并打印输出,但客户端收到如下所示的消息。如何获取XMLRPC服务器(Python 2.7.3)的输出?
C:\CVS\Python\MyTestProject\src>python xmlrpcclient2.py
8
5
2
Traceback (most recent call last):
File "xmlrpcclient2.py", line 8, in <module>
print s.brocade('sh ver')
File "c:\Python27\lib\xmlrpclib.py", line 1224, in __call__
return self.__send(self.__name, args)
File "c:\Python27\lib\xmlrpclib.py", line 1578, in __request
verbose=self.__verbose
File "c:\Python27\lib\xmlrpclib.py", line 1264, in request
return self.single_request(host, handler, request_body, verbose)
File "c:\Python27\lib\xmlrpclib.py", line 1297, in single_request
return self.parse_response(response)
File "c:\Python27\lib\xmlrpclib.py", line 1473, in parse_response
return u.close()
File "c:\Python27\lib\xmlrpclib.py", line 793, in close
raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 1: "<type 'exceptions.TypeError'>:cannot marshal None unless allow_none is enabled">
服务器显示
T06CORE - - [19/Mar/2013 11:11:33] "POST /RPC2 HTTP/1.1" 200 -
T06CORE - - [19/Mar/2013 11:12:04] "POST /RPC2 HTTP/1.1" 200 -
T06CORE - - [19/Mar/2013 11:12:05] "POST /RPC2 HTTP/1.1" 200 -
T06CORE - - [19/Mar/2013 11:12:06] "POST /RPC2 HTTP/1.1" 200 -
All jobs enqueued.
Waiting for the queue to finish.
You have reached Brocade FCF195
cmsh
gets you into the IOS-style management shell.
-----------------------------------------------------------------
broc150_jack:admin> switchshow | grep switchType
switchType: 76.7
broc150_jack:admin> cmsh
broc150_jack#sh ver
←[?1h←=←[K Fabric Operating System Software
Fabric Operating System Version: 7.0
Copyright (c) 1995-2008 Brocade Communications Systems, Inc.
Build Time: 21:52:25 Oct 10, 2012
broc150_jack uptime: 12w4d19h
Firmware name: v7.0.2a
Switch Model Name: Brocade 8000
Control Processor: Freescale Semiconductor 8548E with 1016 MB of memory
4MB of boot flash memory.
8 FC Port(s)
24 Ten GigabitEthernet/IEEE 802.3 interface(s)
←[K ←[?1l←>broc150_jack#10.0.0.150 job is done.
Destroying queue...
Queue destroyed.
T06CORE - - [19/Mar/2013 11:12:08] "POST /RPC2 HTTP/1.1" 200 -
你有)任何想法的客户如何能得到织锦的结果(?
谢谢, Spark。
xmlrpcserver2.py
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler
# Restrict to a particular path.
class RequestHandler(SimpleXMLRPCRequestHandler):
rpc_paths = ('/RPC2',)
# Create server
listening_port = 8002
server = SimpleXMLRPCServer(("localhost", listening_port),
requestHandler=RequestHandler)
print "Listening on port %d..." % listening_port
server.register_multicall_functions()
server.register_introspection_functions()
# Register pow() function; this will use the value of
# pow.__name__ as the name, which is just 'pow'.
server.register_function(pow)
# Register a function under a different name
def adder_function(x,y):
return x + y
server.register_function(adder_function, 'add')
def brocade(str):
import brocade
return brocade.MySwitch().do_something_cool(str)
server.register_function(brocade, 'brocade')
# Register an instance; all the methods of the instance are
# published as XML-RPC methods (in this case, just 'div').
class MyFuncs:
def div(self, x, y):
return x // y
server.register_instance(MyFuncs())
# Run the server's main loop
server.serve_forever()
xmlrpcclient2.py
import xmlrpclib
s = xmlrpclib.ServerProxy('http://localhost:8002')
print s.pow(2,3) # Returns 2**3 = 8
print s.add(2,3) # Returns 5
print s.div(5,2) # Returns 5//2 = 2
print s.brocade('sh ver')
@ToekenMacGuy当我用“ALLOW_NONE”关键字,则返回“无”就在服务器仍在运行越来越开关版本信息的执行。我如何从客户那里获取这些信息? – spark 2013-03-19 21:10:30