In order to make XML-RPC requests use the xmlrpclib module (included in the standard modules) as before but pass the actually network requests off to requests.
As the example reveals there is no use of a server proxy object [as in traditional xmlrpclib usage], method calls are constructed manually using xmlrpclib.dumps but this is a small price to pay for the additional flexibility provided by requests.
import requests, xmlrpclib
payload = xmlrpclib.dumps( ( 10000, 0, ) , 'zogi.getObjectById' )
response = requests.request( 'POST', 'http://coils.wmmi.net/RPC2',
data = payload,
headers = { 'Content-Type': 'application/xml' },
auth = ( 'username', 'password' ),
timeout = 100,
stream = False, )
if response.status_code == 200:
result = xmlrpclib.loads( response.content, )[ 0 ][ 0 ]
print result
else:
# Some error occurred
pass
Text 1: Example call to zogi.getObjectById method
No comments:
Post a Comment