如何使用pythonsuds库创建soap头?
我需要使用如下消息调用SOAP服务:如何使用pythonsuds库创建soap头?,python,soap,header,wsdl,suds,Python,Soap,Header,Wsdl,Suds,我需要使用如下消息调用SOAP服务: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sub="https://secure.xpslogic.com/service/wijnen/sub"> <soapenv:Header> <sub:auth> <token>?</token>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sub="https://secure.xpslogic.com/service/wijnen/sub">
<soapenv:Header>
<sub:auth>
<token>?</token>
<!--Optional:-->
<user_id>?</user_id>
<!--Optional:-->
<user_token>?</user_token>
</sub:auth>
</soapenv:Header>
<soapenv:Body>
<sub:customer_logos_pull>
<!--Optional:-->
<language>?</language>
<!--Optional:-->
<limit>?</limit>
<!--Optional:-->
<options_utc>?</options_utc>
</sub:customer_logos_pull>
</soapenv:Body>
</soapenv:Envelope>
但这会给我一条格式不正确(无效令牌)
消息。打开日志记录时,我发现以下消息:
DEBUG:suds.mx.core:processing:
(Content){
tag = "auth"
value =
(auth){
token = "xxx"
user_id = None
user_token = None
}
type = <Element:0x10ff8c950 name="auth">
<Complex:0x10ff8cbd0>
<Sequence:0x10ff8cc50>
<Element:0x10ff8cd10 name="token" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
<Element:0x10ff8cd50 name="user_id" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
<Element:0x10ff8cd90 name="user_token" type="(u'string', u'http://www.w3.org/2001/XMLSchema')" />
</Sequence>
</Complex>
</Element>
}
及
它在日志中提供了此内容,但仍然是一个格式不正确的(无效令牌)
:
(内容){
tag=“auth”
价值观=
{
token=“xxx”
}
类型=
}
有人知道我如何使用Python在头中正确设置令牌吗?欢迎所有提示 我的soap头工作如下:
from suds.sax.element import Element
ssnp = Element("xsi:SessionHeader").append(Element('xsi:sessionId').setText("xxxxxxx"))
client.set_options(soapheaders=ssnp)
对应于下面在soap请求xml中显示的soap头
<SOAP-ENV:Header>
<xsi:SessionHeader>
<xsi:sessionId>xxxxxxx</xsi:sessionId>
</xsi:SessionHeader>
</SOAP-ENV:Header>
xxxxxxx
我们可以查看使用打印客户端发送的请求。上次发送()我尝试使用
from suds.client import Client
WSDL_URL='http://apitest.comune.genova.it:28280/MANU_WSManutenzioni_MOGE/'
#Create the Client:
print("Print 1")
client = Client(url=WSDL_URL)
print("Print 2")
from suds.sax.element import Element
ssnp = Element("xsi:SessionHeader").append(Element('xsi:Authorization').setText("XXXXXXXXXXX"))
client.set_options(soapheaders=ssnp)
但是我在下面的行中遇到了一个错误
client = Client(url=WSDL_URL)
下面是错误:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/suds/transport/http.py", line 67, in open
return self.u2open(u2request)
File "/usr/local/lib/python3.6/site-packages/suds/transport/http.py", line 132, in u2open
return url.open(u2request, timeout=tm)
File "/usr/lib64/python3.6/urllib/request.py", line 532, in open
response = meth(req, response)
File "/usr/lib64/python3.6/urllib/request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib64/python3.6/urllib/request.py", line 570, in error
return self._call_chain(*args)
File "/usr/lib64/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/usr/lib64/python3.6/urllib/request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 405: Method Not Allowed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test_ws.py", line 44, in <module>
client = Client(url=WSDL_URL)
File "/usr/local/lib/python3.6/site-packages/suds/client.py", line 115, in __init__
self.wsdl = reader.open(url)
File "/usr/local/lib/python3.6/site-packages/suds/reader.py", line 151, in open
d = self.fn(url, self.options)
File "/usr/local/lib/python3.6/site-packages/suds/wsdl.py", line 136, in __init__
d = reader.open(url)
File "/usr/local/lib/python3.6/site-packages/suds/reader.py", line 78, in open
d = self.download(url)
File "/usr/local/lib/python3.6/site-packages/suds/reader.py", line 94, in download
fp = self.options.transport.open(Request(url))
File "/usr/local/lib/python3.6/site-packages/suds/transport/https.py", line 62, in open
return HttpTransport.open(self, request)
File "/usr/local/lib/python3.6/site-packages/suds/transport/http.py", line 69, in open
raise TransportError(str(e), e.code, e.fp)
suds.transport.TransportError: HTTP Error 405: Method Not Allowed
回溯(最近一次呼叫最后一次):
打开文件“/usr/local/lib/python3.6/site packages/suds/transport/http.py”,第67行
返回self.u2open(u2request)
文件“/usr/local/lib/python3.6/site packages/suds/transport/http.py”,第132行,打开
返回url.open(u2request,timeout=tm)
打开文件“/usr/lib64/python3.6/urllib/request.py”,第532行
响应=方法(请求,响应)
文件“/usr/lib64/python3.6/urllib/request.py”,第642行,在http\u响应中
“http”、请求、响应、代码、消息、hdrs)
文件“/usr/lib64/python3.6/urllib/request.py”,第570行出错
返回自我。调用链(*args)
文件“/usr/lib64/python3.6/urllib/request.py”,第504行,在调用链中
结果=func(*args)
文件“/usr/lib64/python3.6/urllib/request.py”,第650行,默认为http\u error\u
raise HTTPError(请求完整的url、代码、消息、hdrs、fp)
urllib.error.HTTPError:HTTP错误405:不允许使用方法
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“test_ws.py”,第44行,在
客户端=客户端(url=WSDL\U url)
文件“/usr/local/lib/python3.6/site packages/suds/client.py”,第115行,在__
self.wsdl=reader.open(url)
文件“/usr/local/lib/python3.6/site packages/suds/reader.py”,第151行,打开
d=self.fn(url,self.options)
文件“/usr/local/lib/python3.6/site packages/suds/wsdl.py”,第136行,在__
d=读卡器。打开(url)
文件“/usr/local/lib/python3.6/site packages/suds/reader.py”,第78行,打开
d=自我下载(url)
文件“/usr/local/lib/python3.6/site packages/suds/reader.py”,第94行,下载
fp=self.options.transport.open(请求(url))
文件“/usr/local/lib/python3.6/site packages/suds/transport/https.py”,第62行,打开
返回HttpTransport.open(self,request)
打开文件“/usr/local/lib/python3.6/site packages/suds/transport/http.py”,第69行
raise传输错误(str(e)、e.code、e.fp)
suds.transport.TransportError:HTTP错误405:不允许使用方法
您是如何通过日志设置日志格式的?如果需要设置多个soap头,请参阅
<SOAP-ENV:Header>
<xsi:SessionHeader>
<xsi:sessionId>xxxxxxx</xsi:sessionId>
</xsi:SessionHeader>
</SOAP-ENV:Header>
from suds.client import Client
WSDL_URL='http://apitest.comune.genova.it:28280/MANU_WSManutenzioni_MOGE/'
#Create the Client:
print("Print 1")
client = Client(url=WSDL_URL)
print("Print 2")
from suds.sax.element import Element
ssnp = Element("xsi:SessionHeader").append(Element('xsi:Authorization').setText("XXXXXXXXXXX"))
client.set_options(soapheaders=ssnp)
client = Client(url=WSDL_URL)
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/suds/transport/http.py", line 67, in open
return self.u2open(u2request)
File "/usr/local/lib/python3.6/site-packages/suds/transport/http.py", line 132, in u2open
return url.open(u2request, timeout=tm)
File "/usr/lib64/python3.6/urllib/request.py", line 532, in open
response = meth(req, response)
File "/usr/lib64/python3.6/urllib/request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib64/python3.6/urllib/request.py", line 570, in error
return self._call_chain(*args)
File "/usr/lib64/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/usr/lib64/python3.6/urllib/request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 405: Method Not Allowed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test_ws.py", line 44, in <module>
client = Client(url=WSDL_URL)
File "/usr/local/lib/python3.6/site-packages/suds/client.py", line 115, in __init__
self.wsdl = reader.open(url)
File "/usr/local/lib/python3.6/site-packages/suds/reader.py", line 151, in open
d = self.fn(url, self.options)
File "/usr/local/lib/python3.6/site-packages/suds/wsdl.py", line 136, in __init__
d = reader.open(url)
File "/usr/local/lib/python3.6/site-packages/suds/reader.py", line 78, in open
d = self.download(url)
File "/usr/local/lib/python3.6/site-packages/suds/reader.py", line 94, in download
fp = self.options.transport.open(Request(url))
File "/usr/local/lib/python3.6/site-packages/suds/transport/https.py", line 62, in open
return HttpTransport.open(self, request)
File "/usr/local/lib/python3.6/site-packages/suds/transport/http.py", line 69, in open
raise TransportError(str(e), e.code, e.fp)
suds.transport.TransportError: HTTP Error 405: Method Not Allowed