如何解决SOAP 请求因错误而失败 验证消息的安全性时发生错误
被 SOAP 请求困住了。
我用来发出请求的代码:
def get_body():
import datetime
today_datetime = datetime.datetime.today() - datetime.timedelta(minutes=1)
expires_datetime = today_datetime + datetime.timedelta(minutes=5)
body = """
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">http://edd.ca.gov/IFsetService/Ping</a:Action>
<a:MessageID>urn:uuid:{}</a:MessageID>
<a:ReplyTo>
<a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">https://fsettestprod.edd.ca.gov/fsetwcfproxywebservice/fsetservice.svc</a:To>
<o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis200401-wss-wssecurity-secext-1.0.xsd">
<u:Timestamp u:Id="{}">
<u:Created>{}</u:Created>
<u:Expires>{}</u:Expires>
</u:Timestamp>
<o:Usernametoken u:Id="{}">
<o:Username>xxxxxxxxx</o:Username>
<o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-usernametoken-profile-1.0#PasswordText">xxxxxx</o:Password>
</o:Usernametoken>
</o:Security>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Ping xmlns="http://edd.ca.gov/"/>
</s:Body>
</s:Envelope>"""
body = body.format(uuid.uuid4(),uuid.uuid4(),today_datetime.strftime("%Y-%m-%dT%H:%M:%sZ"),expires_datetime.strftime("%Y-%m-%dT%H:%M:%sZ"),uuid.uuid4())
return body
headers = {"content-type" : "text/xml"}
res = requests.post(url,data=get_body(),headers=headers)
错误:
--uuid:4bef2eb8-ccb6-4c06-8c85-526b0fcf07e2+id=545
Content-ID: <http://tempuri.org/0>
Content-transfer-encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2004/08/addressing/fault</a:Action><a:RelatesTo>urn:uuid:2f5ce100-17c7-49f8-9bfe-9d5319c28566</a:RelatesTo><a:To s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:To></s:Header><s:Body><s:Fault><faultcode xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">a:InvalidSecurity</faultcode><faultstring xml:lang="en-US">An error occurred when verifying security for the message.</faultstring></s:Fault></s:Body></s:Envelope>
--uuid:4bef2eb8-ccb6-4c06-8c85-526b0fcf07e2+id=545--
WSDL 链接:https://fsettestprod.edd.ca.gov/fsetwcfproxywebservice/fsetservice.svc?wsdl
我使用的凭据是正确的,但请求仍然失败。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。