Here is my xmlrpc server python code.I want to change response.
from SimpleXMLRPCServer import SimpleXMLRPCServer
import logger
import db_connect
# Set up logging
logger.Logger(name="rpc", address="rpc.log")
server = SimpleXMLRPCServer(('0.0.0.0', 4242), logRequests=True)
# Expose a function
def get_status(extension):
status=db_connect.get_status(extension)
logger.logger().info(" extension number %s Found %s
",extension,status )
return status
server.register_function(get_status)
try:
print ('Use Control-C to exit')
server.serve_forever()
except KeyboardInterrupt:
print ('Exiting')
Xml rpc server return the following response to the client.
<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value><boolean>0</boolean></value>
</param>
</params>
</methodResponse>
Is it possible to return customize response like below?
<?xml version='1.0'?>
<Status>
<Extension>605</Extension>
<Bite_Status>Operational Fault</Bite_Status>
<Iridium_Channels_Available>0</Iridium_Channels_Available>
<DND_State>Disabled</DND_State>
<DND_Override>Disabled</DND_Override>
<Mute_State>Disabled</Mute_State>
</Status>
Also want to change http header response status code.
If you want to return multiple, potentially nested elements from your xmlrpc server, have your function return a dictionary:
This will return the xml below; it's more verbose than you're example as it has to conform to the xmlrpc specification. If you're using the standard library's ServerProxy as your client the xml would be converted to a dictionary the same as that generated by the server function.
The status code is hardcoded in the server implementation, so it cannot be changed unless you write your own server. Note also that a return code of 200 is required by the xlmrpc specification for successful responses.