SOAP 请求因错误而失败 验证消息的安全性时发生错误

时间:2021-03-18 10:56:54

标签: python soap wsse

被 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

我使用的凭据是正确的,但请求仍然失败。

我在这里遗漏了一些标题吗?

0 个答案:

没有答案