Created
May 15, 2013 16:08
-
-
Save akx/5585146 to your computer and use it in GitHub Desktop.
Simple uWSGI + XML-RPC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xmlrpclib | |
s = xmlrpclib.ServerProxy('http://localhost:3040') | |
print s.pow(2,3) | |
print s.sum([2,3]) | |
print s.system.listMethods() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Very usefull for SimpleJSONRPCServer too from package https://github.com/joshmarshall/jsonrpclib!
Thank you very much, that's what I was looking for.