我不熟悉SOAP请求和编程。我想访问一个需要承载令牌授权才能使用其中一个服务的WSDL。在
有关调用pyhton -mzeep *WSDL_url*
后要访问的服务的信息:
getInfo(param1: xsd:string, param2: xsd:anySimpleType, param3: xsd:anySimpleType) -> out: ns0:ResponseCurve[]
首先,我收到的代币是:
^{pr2}$然后我想请求需要三个参数的getInfo服务:
my_info = client.service.getInfo('param1', 'param2', 'param3')
我通过提供者知道,每次我想访问此服务时都需要该令牌,并且在文档中,有关身份验证的头的说明如下:
授权:持有人eyJhbGciOiJIUzI1N[…]
我试图在_soapheaders
中以dict形式传递头,但没有成功。在
我可以使用强制请求访问服务:
def get_response_from_provider(token, param1, param2, param3):
url = "WSDL url"
headers = {'Authorization': 'Bearer ' + token,
'content-type': 'text/xml'}
body = """
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsl="uri">
<soapenv:Header/>
<soapenv:Body>
<wsl:getInfo>
<param1>""" + param1 + """</param1>
<param2>""" + param2 + """ </param2>
<param3>""" + param3 + """ </param3>
</wsl:getInfo>
</soapenv:Body>
</soapenv:Envelope>"""
response = requests.post(url, data=body, headers=headers)
print("Info recieved...")
return response
但是我想通过SOAP客户机访问服务。在
这是他们在PHP中添加令牌的方式:
$soap->soapClient->_stream_context = stream_context_create([
'http' => [
'header' => sprintf('Authorization: Bearer %s', $authTokenResponse->token)
]
]);
关于如何在Python中将带有令牌的头添加到客户机请求中吗??在
我在SOF中看到过很多SOAP+Python的帖子,但都不能解决这个问题。即使有了Zeep文档,我也没能让它发挥作用。在
谢谢
我想做一些类似的事情,结果是在文档上,但有点隐藏,你可以在这里找到它:
https://python-zeep.readthedocs.io/en/master/settings.html#context-manager
简而言之,你可以做一些事情,比如:
相关问题 更多 >
编程相关推荐