Skip to content

Instantly share code, notes, and snippets.

@akx
Created May 15, 2013 16:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save akx/5585146 to your computer and use it in GitHub Desktop.
Save akx/5585146 to your computer and use it in GitHub Desktop.
Simple uWSGI + XML-RPC
import xmlrpclib
s = xmlrpclib.ServerProxy('http://localhost:3040')
print s.pow(2,3)
print s.sum([2,3])
print s.system.listMethods()
# start uwsgi with this app, listening with http on some port
uwsgi --wsgi xmlrpc_server --http :3040
# in another window
python client.py
# output should be 8, 5 and a list of functions
from SimpleXMLRPCServer import SimpleXMLRPCDispatcher
dispatch = SimpleXMLRPCDispatcher()
dispatch.register_introspection_functions()
dispatch.register_function(pow)
dispatch.register_function(sum)
def application(environ, start_response):
if environ["REQUEST_METHOD"] != "POST":
start_response("500 Error", ())
return ["Only POST allowed"]
try:
length = int(environ.get('CONTENT_LENGTH', None))
except (TypeError, ValueError):
length = -1
request_text = environ["wsgi.input"].read(length)
response = dispatch._marshaled_dispatch(request_text)
start_response("200 OK", [("Content-Type", "text/xml"), ("Content-Length", str(len(response)))])
return response
@vartagg
Copy link

vartagg commented May 30, 2014

Very usefull for SimpleJSONRPCServer too from package https://github.com/joshmarshall/jsonrpclib!
Thank you very much, that's what I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment