如何使用Python SOAPpy访问Yahoo Enterprise Web Services?

时间:2009-03-18 09:08:58

标签: python soap soappy

我有一个可以运行的PHP脚本,我需要在Python中编写相同的内容,但SOAPpy会生成稍微不同的请求,我不知道如何修复它,以便服务器喜欢它。

php脚本生成的请求如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://marketing.ews.yahooapis.com/V4"
>
<SOAP-ENV:Header>
<ns1:username>*****</ns1:username>
<ns1:password>*****</ns1:password>
<ns1:masterAccountID>*****</ns1:masterAccountID>
<ns1:accountID>6674262970</ns1:accountID>
<ns1:license>*****</ns1:license>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getCampaignsByAccountID>
<ns1:accountID>6674262970</ns1:accountID>
<ns1:includeDeleted>false</ns1:includeDeleted>
</ns1:getCampaignsByAccountID>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

当尝试使用SOAPPy进行相同操作时,我得到了这个请求:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>
<SOAP-ENV:Header>
<username xsi:type="xsd:string">*****</username>
<masterAccountID xsi:type="xsd:string">*****</masterAccountID>
<license xsi:type="xsd:string">*****</license>
<accountID xsi:type="xsd:integer">6674262970</accountID>
<password xsi:type="xsd:string">*****</password>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getCampaignsByAccountID xmlns:ns1="http://marketing.ews.yahooapis.com/V4">
<includeDeleted xsi:type="xsd:boolean">False</includeDeleted>
<accountID xsi:type="xsd:integer">6674262970</accountID>
</ns1:getCampaignsByAccountID>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

略有不同的请求,但我想它应该可以工作,但我从服务器收到错误:“

中指定的帐户ID

标题与参数中指定的标题不匹配。“

但他们匹配!

我唯一看到的是命名空间的一些差异,但我不知道现在该做什么。请帮忙。

2 个答案:

答案 0 :(得分:2)

问题不在于SOAP头格式,而在于参数顺序。以下是完整的解释和代码:http://pea.somemilk.org/2009/04/05/yahoo-search-marketing-python-soap-binding/

答案 1 :(得分:0)

accountID应为xsd:string类型,而不是xsd:integer。 (也许你传递一个字符串而不是一个整数,这就是为什么SOAPpy这样做的原因?)