Passing parameters using XML-RPC client in Python

时间:2016-12-23 09:32:06

标签: python api xml-rpc

I have an API key, which I can use via Chrome (XML RPC Client extension, with JSON array input) or with Firefox extension (RESTClient extension, with XML data input). I want to do it in Python.

I can list methods, but I have no idea how to pass complex things.

Here is the code which returns methods:

import xmlrpc.client

with xmlrpc.client.ServerProxy("http://a4a.test.clickonometrics.pl/api/xmlrpc.php") as proxy:
    response=proxy.system.listMethods()
    print(response)

I want to use method "publisher.getStats" and pass JSON Array:

["bOpd4YbxbQXZxa7n1Aj4PbsRbviz1Jlk",{"perspective":"campaigns","date_start":"2016-08-01","date_end":"2016-12-31","ids":["534"],"group":"placements"}]

It works 1:1 as I described in Chrome XML-RPC Client extension.

How to do it in Python?

1 个答案:

答案 0 :(得分:0)

我终于成功了。

方法名称应该像proxy.methodname一样传递,参数在常规括号中传递,不带[]。真的很简单,但我花了一些时间。

工作代码:

import xmlrpc.client

with xmlrpc.client.ServerProxy("http://a4a.test.clickonometrics.pl/api/xmlrpc.php") as proxy:
    response=proxy.publisher.getStats("bOpd4YbxbQXZxa7n1Aj4PbsRbviz1Jlk",{"perspective":"campaigns","date_start":"2016-08-01","date_end":"2016-12-31","ids":["534"],"group":"placements"})
    print(response)