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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...