简体   繁体   English

在Python中使用XML-RPC客户端传递参数

[英]Passing parameters using XML-RPC client in Python

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). 我有一个API密钥,可以通过Chrome(XML RPC客户端扩展,带有JSON数组输入)或Firefox扩展(RESTClient扩展,带有XML数据输入)使用。 I want to do it in Python. 我想用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: 我想使用方法“ publisher.getStats”并传递JSON Array:

["bOpd4YbxbQXZxa7n1Aj4PbsRbviz1Jlk",{"perspective":"campaigns","date_start":"2016-08-01","date_end":"2016-12-31","ids":["534"],"group":"placements"}] [“ bOpd4YbxbQXZxa7n1Aj4PbsRbviz1Jlk”,{“ perspective”:“ campaigns”,“ date_start”:“ 2016-08-01”,“ date_end”:“ 2016-12-31”,“ ids”:[“ 534”],“ group “:”展示位置“}]

It works 1:1 as I described in Chrome XML-RPC Client extension. 正如我在Chrome XML-RPC客户端扩展中所述,它的工作方式为1:1。

How to do it in Python? 如何在Python中完成?

I finally managed to do it. 我终于做到了。

The method name should be passed like proxy.methodname , and the parameters in regular brackets, just without []. 方法名称应像proxy.methodname一样proxy.methodname ,并且将参数放在常规方括号中,只是不带[]。 Really simple, but it took me some time. 真的很简单,但是花了我一些时间。

Working code: 工作代码:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM