开发者

Python HTTP server with XML-RPC

I have a server that has to respond to HTTP and XML-RPC requests. Right now I have an instance of SimpleXMLRPCServer, and an instance of BaseHTTPServer.HTTPServer with a custom request handler, running on different ports. I'd like to run both services on a single port.

I think it should be possible to modify the CGIXMLRPCRequestHandler class to also serve custom HTTP requests on some paths, or alternately, to use multiple requ开发者_如何学JAVAest handlers based on what path is requested. I'm not really sure what the cleanest way to do this would be, though.


Use SimpleXMLRPCDispatcher class directly from your own request handler.


Is there a reason not to run a real webserver out front with url rewrites to the two ports you are usign now? It's going to make life much easier in the long run


Simplest way would be (tested for Python 3.3 but should work for 2.x with modified imports):

from http.server import SimpleHTTPRequestHandler
from xmlrpc.server import SimpleXMLRPCRequestHandler,SimpleXMLRPCServer

class MixRequestHandler(SimpleHTTPRequestHandler,SimpleXMLRPCRequestHandler):
    pass

srv=SimpleXMLRPCServer(("localhost",8080),MixRequestHandler)
#normal stuff for SimpleXMLRPCServer
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜