私はまだSOAPに新しいことがあり、何がうまくいかなければならないと言います。 Vertical Response APIで作業しています。配列の配列が入れ子になっていない
要求に対してxmlを正しく構築するためにsudsを取得するのに問題があります。ここにいくつかのコードがあります:
from suds.client import Client
url = 'https://api.verticalresponse.com/wsdl/1.0/VRAPI.wsdl'
client = Client(url)
vr = client.service
...
test_list = (
(
{
'name' : 'email_address',
'value' : login['username'],
},
{
'name' : 'First_Name',
'value' : 'VR_User',
}
),
(
{
'name' : 'email_address',
'value' : '[email protected]',
},
{
'name' : 'First_Name',
'value' : login['username'],
},
),
)
# sid and cid are correctly retrieved prior to this point
print "Sending test message..."
vr.sendEmailCampaignTest({
'session_id' : sid,
'campaign_id' : cid,
'recipients' : test_list,
})
ここでログイン['username']は電子メールアドレスです。
このコードは、このエラーが発生します。ここでは
suds.WebFault: Server raised fault: 'Application failed during request deserialization: Too many elements in array. 4 instead of claimed 2 (2)
はsendEmailCampaignTestの定義です: http://developers.verticalresponse.com/api/soap/methods/campaigns/sendemailcampaigntest/
ここでの出力をログに記録xmlです。私は(垂直レスポンスによって提供される)以下のルビーのスクリプトに基づいて私のスクリプトを移植しています
<?xml version="1.0" encoding="utf-8" ?>
DEBUG:suds.client:headers = {'SOAPAction': u'"VR/API/1_0#sendEmailCampaignTest"', 'Content-Type': 'text/xml; charset=utf-8'}
ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://api.verticalresponse.com/1.0/VRAPI.xsd" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="VR/API/1_0" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header/>
<ns0:Body>
<ns4:sendEmailCampaignTest>
<args xsi:type="ns3:sendEmailCampaignTestArgs">
<session_id xsi:type="ns1:string">redacted</session_id>
<campaign_id xsi:type="ns1:int">redacted</campaign_id>
<recipients xsi:type="ns3:ArrayOfNVDictionary" ns2:arrayType="ns3:NVDictionary[2]">
<item>
<name xsi:type="ns1:string">email_address</name>
<value xsi:type="ns1:string">[email protected]</value>
</item>
<item>
<name xsi:type="ns1:string">First_Name</name>
<value xsi:type="ns1:string">VR_User</value>
</item>
<item>
<name xsi:type="ns1:string">email_address</name>
<value xsi:type="ns1:string">[email protected]</value>
</item>
<item>
<name xsi:type="ns1:string">First_Name</name>
<value xsi:type="ns1:string">[email protected]</value>
</item>
</recipients>
</args>
</ns4:sendEmailCampaignTest>
</ns0:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:http failed:
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Client</faultcode><faultstring>Application failed during request deserialization: Too many elements in array. 4 instead of claimed 2 (2)
</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
:
このXMLが間違っているとを動作しません(私はSESSION_IDと、ここで表示するためにLIST_IDを削除しました)test_list = [
[{
'name' => 'email_address',
'value' => $username
},
{
'name' => 'First_Name',
'value' => 'VR_User'
}
],
[{
'name' => 'email_address',
'value' => '[email protected]'
},
{
'name' => 'First_Name',
'value' => $username
}
]
]
print "Sending test message...\n"
temp0 = vr.sendEmailCampaignTest({
'session_id' => sid,
'campaign_id' => cid,
'recipients' => test_list,
})
次のxmlを出力します。私はエラーが受信者の建設であることを理解
<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<n1:sendEmailCampaignTest xmlns:n1="VR/API/1_0"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<args xmlns:n2="http://api.verticalresponse.com/1.0/VRAPI.xsd"
xsi:type="n2:sendEmailCampaignTestArgs">
<session_id xsi:type="xsd:string">redacted</session_id>
<campaign_id xsi:type="xsd:int">redacted</campaign_id>
<recipients xmlns:n3="http://schemas.xmlsoap.org/soap/encoding/"
xsi:type="n3:Array"
n3:arrayType="n2:NVDictionary[2]">
<item xsi:type="n3:Array"
n3:arrayType="n2:NVPair[2]">
<item>
<name xsi:type="xsd:string">email_address</name>
<value href="#id9496430"></value>
</item>
<item>
<name xsi:type="xsd:string">First_Name</name>
<value xsi:type="xsd:string">VR_User</value>
</item>
</item>
<item xsi:type="n3:Array"
n3:arrayType="n2:NVPair[2]">
<item>
<name xsi:type="xsd:string">email_address</name>
<value xsi:type="xsd:string">[email protected]</value>
</item>
<item>
<name xsi:type="xsd:string">First_Name</name>
<value href="#id9496430"></value>
</item>
</item>
</recipients>
</args>
</n1:sendEmailCampaignTest>
<value id="id9496430"
xsi:type="xsd:string"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">[email protected]</value>
</env:Body>
</env:Envelope>
:このXMLが正しいとに動作します(私はSESSION_IDとLIST_IDを削除しました)。 2つの項目を含む2つの項目が必要です。それぞれに2つの項目が含まれていますが、sudsを使用するPythonスクリプトでは、4つのネストされていない項目が含まれています。だから私の質問は、私は正しくXMLを構築するために泡を得ることができますか?
編集:私が試したもの:
>>> url = 'https://api.verticalresponse.com/wsdl/1.0/VRAPI.wsdl'
>>> client = Client(url)
>>> args = client.factory.create('ns0:sendEmailCampaignTestArgs')
>>> args
(sendEmailCampaignTestArgs){
session_id = None
campaign_id = None
recipients =
(ArrayOfNVDictionary){
_arrayType = ""
_offset = ""
_id = ""
_href = ""
_arrayType = ""
}
}
ArrayOfNVDictionaryが泡によって正しく構築されていないように私には見えるが(それはNVDictionaryのを開催する実際の配列要素を持っていない)、任意のあなたが偉大になると思うのを助けてください。
[OK]を(私はまた、(nvdict)を追加するのではなく、args.recipients.append(受取人)に変更しました。それについてのアイデアはありますか? – joshcartme
@joshcartme:理想的な世界では、args.recipientsは配列のように見えますが、SOAPは非常に乱雑な標準ですが、時には泡がWSDLを理解できないことがあります。ループの前に 'args.recipients = []'を試してみてください。 –
受信者= []それは私に次のエラーを与える:suds.WebFault:サーバーはエラーを発生させました: 'ARRAYリファレンスではありません。私もtest_listを構築する方法のあなたの他の提案を試み、同じエラーを生成しました。これまでの助けてくれてありがとう。 – joshcartme