Python 修复sudsoap请求中的传出消息
调用soap WS后,我的suds请求生成无效消息。Python 修复sudsoap请求中的传出消息,python,soap,suds,Python,Soap,Suds,调用soap WS后,我的suds请求生成无效消息。 有两件事我花了几个小时却没有成功: 将命名空间和前缀添加到一个复杂的OBEJCT(securityObject) 将属性添加到另一个复杂对象(文档) 我的客户: Suds ( https://fedorahosted.org/suds/ ) version: 0.6 Service ( MyService ) tns="http://path/to/tns" Prefixes (4) ns0 = "http://pat
有两件事我花了几个小时却没有成功:
- 将命名空间和前缀添加到一个复杂的OBEJCT(
)securityObject
- 将属性添加到另一个复杂对象(
)文档
Suds ( https://fedorahosted.org/suds/ ) version: 0.6
Service ( MyService ) tns="http://path/to/tns"
Prefixes (4)
ns0 = "http://path/to/v3/"
ns1 = "http://path/to/tns"
ns2 = "http://www.path/to/file.001.xsd"
ns3 = "http://www.path/to/file.002.xsd"
Ports (1):
(MyServiceSOAP)
Methods (1):
processAction(ns2:Document Document, ns0:securityObject securityObject PriorityType priority)
Types (233):
ns0:securityObject
PriorityType
ns3:Document
ns2:Document
ns3:AccountIdentification4Choice
…
1st方法参数:
因为ns2:Document Document
非常大和复杂,而且我已经有了有效的XML,所以我将以以下形式将其作为processAction
参数传递:
from suds.sax.text import Raw
_doc.open('file.xml').read()
doc = Raw(_doc) # ready to pass
此文档的外观如下所示:
…
第二个方法参数:
是安全对象:
s_o = client.factory.create('{http://path/to/v3/}securityObject')
s_o.name = token_data.Name
s_o.user = token_data.Tenant
s_o.timestamp = token_data.Time.isoformat()
s_o.pass = token_data.Passwd
让我们发送:
try:
process_data = client.service.processAction(s_o, doc, prio.NORMAL)
except suds.WebFault as e:
print e
传出(无效)消息:
非常感谢您的帮助,谢谢 在那里
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" # in client its "http://path/to/v3/"
xmlns:ns1="http://path/to/tns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
# missing xmlns:v3="http://path/to/v3/" here!
<SOAP-ENV:Header/>
<ns0:Body>
<ns1:payment>
<securityObject> # wrong! shall be <v3:securityObject>
<user>1</user>
<name>MyName</name>
<timestamp>2016-06-22T11:40:58.115000+02:00</timestamp>
<pass>Password</pass>
</securityObject>
<Document> # wrong, missing attribute here, xmlns=
<Document xmlns="http://www.path/to/file.001.xsd"> # comes from orginal xml, can be trimmed
xmlns:v3="http://path/to/v3/" # this to be added in Envelope
<v3:securityObject>
...
</v3:securityObject>
(Content){
tag = "Document"
value = "<Document xmlns="http://www.path/to/file.001.xsd">
<CfInitn>
<GrpHdr>
...
(Content){
tag = "securityObject"
value =
(securityObject){
user= 1
name = "MyName"
timestamp = "2016-06-22T12:51:29.820000+02:00"
pass= "Password"
}