Skip to content

Instantly share code, notes, and snippets.

@tsaridas
Forked from akx/client.py
Created May 21, 2017 18:53
Show Gist options
  • Select an option

  • Save tsaridas/867c496cd1338df66f7412e8fd5bda55 to your computer and use it in GitHub Desktop.

Select an option

Save tsaridas/867c496cd1338df66f7412e8fd5bda55 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment