| 1 |
# Copyright (c) Twisted Matrix Laboratories. |
| 2 |
# See LICENSE for details. |
| 3 |
|
| 4 |
""" |
| 5 |
This example makes remote XML-RPC calls. |
| 6 |
|
| 7 |
Usage: |
| 8 |
$ python xmlrpcclient.py |
| 9 |
|
| 10 |
The example will make an XML-RPC request to advogato.org and display the result. |
| 11 |
""" |
| 12 |
|
| 13 |
from twisted.internet import reactor |
| 14 |
from twisted.web.xmlrpc import Proxy |
| 15 |
|
| 16 |
|
| 17 |
def printValue(value): |
| 18 |
print(repr(value)) |
| 19 |
reactor.stop() |
| 20 |
|
| 21 |
|
| 22 |
def printError(error): |
| 23 |
print("error", error) |
| 24 |
reactor.stop() |
| 25 |
|
| 26 |
|
| 27 |
def capitalize(value): |
| 28 |
print(repr(value)) |
| 29 |
proxy.callRemote("test.capitalize", "moshe zadka").addCallbacks( |
| 30 |
printValue, printError |
| 31 |
) |
| 32 |
|
| 33 |
|
| 34 |
proxy = Proxy(b"http://advogato.org/XMLRPC") |
| 35 |
# The callRemote method accepts a method name and an argument list. |
| 36 |
proxy.callRemote("test.sumprod", 2, 5).addCallbacks(capitalize, printError) |
| 37 |
reactor.run() |