【问题标题】:Passing parameters using XML-RPC client in Python在 Python 中使用 XML-RPC 客户端传递参数
【发布时间】:2016-12-23 09:32:05
【问题描述】:

我有一个 API 密钥,我可以通过 Chrome(XML RPC 客户端扩展,带有 JSON 数组输入)或 Firefox 扩展(RESTClient 扩展,带有 XML 数据输入)使用它。 我想用 Python 来做。

我可以列出方法,但我不知道如何传递复杂的东西。

这是返回方法的代码:

import xmlrpc.client

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

我想使用方法“publisher.getStats”并传递 JSON 数组:

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

正如我在 Chrome XML-RPC 客户端扩展中描述的那样,它可以 1:1 工作。

如何在 Python 中做到这一点?

【问题讨论】:

    标签: python api xml-rpc


    【解决方案1】:

    我终于成功了。

    方法名应该像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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-15
      • 2016-10-13
      • 1970-01-01
      • 1970-01-01
      • 2013-02-17
      • 2011-07-24
      • 1970-01-01
      • 2012-04-29
      相关资源
      最近更新 更多