带有Python请求的SOAP请求-身份验证错误

时间:2018-10-23 19:02:19

标签: authentication python-requests soap-client

我一直在尝试向SOAP客户端发出请求,但是我一直收到验证错误。

import requests
url="https://10.xx.xx.xx:443/ws/auth.asmx"

headers = {'content-type': 'application/soap+xml'}
body = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:aut="http://authws.worldsys.com.ar/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<aut:AuthenticateUser>
<!--Optional:-->
<aut:username>xxxxxxxxxx</aut:username>
<!--Optional:-->
<aut:password>xxxxxxxx</aut:password>
</aut:AuthenticateUser>
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope>"""

response = requests.post(url,data=body,headers=headers)
print (response.content)

记录错误的响应

requests.exceptions.SSLError: HTTPSConnectionPool(host='10.xx.xx.xx', port=443): Max retries exceeded with url: /ws/auth.asmx (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)')))

使用SoapUI发出的请求可以正常工作

The request made in SoapUI

The answer from SoapUI

当将此代码与不需要身份验证的公共Web服务一起使用时,我确实得到了响应。例如

import requests
url="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"

headers = {'content-type': 'text/xml'}
body = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="http://ws.cdyne.com/WeatherWS/" 
xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body><ns0:GetWeatherInformation/></ns1:Body>
</SOAP-ENV:Envelope>"""

response = requests.post(url,data=body,headers=headers)
print (response.content)

0 个答案:

没有答案