Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用pythonzeep更改SOAP请求中的xmlns:wsse命名空间_Python_Python 3.x_Soap_Xml Namespaces_Zeep - Fatal编程技术网

使用pythonzeep更改SOAP请求中的xmlns:wsse命名空间

使用pythonzeep更改SOAP请求中的xmlns:wsse命名空间,python,python-3.x,soap,xml-namespaces,zeep,Python,Python 3.x,Soap,Xml Namespaces,Zeep,当使用Zeep(Python3.7)向SOAP API发送数据时,会生成wsse:Security头http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd 此操作的结果是错误: zeep.exceptions.Fault: SOAP Security Header UsernameToken is required for operation 'ProcessMessage' 如果我随后

当使用Zeep(Python3.7)向SOAP API发送数据时,会生成
wsse:Security
http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd

此操作的结果是错误:

zeep.exceptions.Fault: SOAP Security Header UsernameToken is required for operation 'ProcessMessage'
如果我随后获取原始请求XML并将其发送到API(通过SOAPUI),我会遇到同样的问题。但是,如果我将此值更改为示例中的值,我将与
WSDL一起发送http://schemas.xmlsoap.org/ws/2002/07/secext
,请求成功完成,我从API获得成功响应

我尝试了很多方法,包括在安全元素头中明确定义名称空间:

header = xsd.Element(
    '{http://schemas.xmlsoap.org/ws/2002/07/secext}Security',
    xsd.ComplexType([
        xsd.Element(
            'UsernameToken',
            xsd.ComplexType([
                xsd.Element('Username', xsd.String()),
                xsd.Element('Password', xsd.String()),
            ])
        )
    ])
)
然而,这似乎并不能解决问题

我也试过:

client.set\u default\u soapheaders([header\u value])
再一次,没有快乐

在Zeep中是否有这样做的方法(我对另一个SOAP包持开放态度,尽管Zeep似乎是最积极维护的)?或者我的请求格式中完全遗漏了可能导致此问题的内容

代码如下。提前谢谢你

header=xsd.Element(
“安全”,
xsd.ComplexType([
元素(
“UsernameToken”,
xsd.ComplexType([
元素('Username',xsd.String()),
元素('Password',xsd.String()),
])
)
])
)
header\u value=header(UsernameToken={'Username':user,'Password':Password})
client.service.ProcessMessage(\u soapheaders=[header\u value],Payload=dataobj)
就生成的XML而言,上面的示例给出了以下内容:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">
  <soap-env:Header>
    <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <wsse:UsernameToken>
        <wsse:Username>username</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
      </wsse:UsernameToken>
    </wsse:Security>
  </soap-env:Header>
  <soap-env:Body>
      ### REQUEST BODY
  </soap-env:Body>
</soap-env:Envelope>

用户名
密码
###请求主体
这是行不通的


但是,只需将
wsse:Security xmlns:wsse
值更改为
http://schemas.xmlsoap.org/ws/2002/07/secext
并将其粘贴到SOAPUI中,这是可行的。

通过切换到使用其他SOAP库解决。

通过切换到使用其他SOAP库解决。

花了我2天时间,但找到了解决方法。 接受

)

然后像这样将名称空间URL信息添加到所有属性,而不仅仅是组

  header = xsd.Element(
'{http://schemas.xmlsoap.org/ws/2002/07/secext}Security',
xsd.ComplexType([
    xsd.Element(
        '{http://schemas.xmlsoap.org/ws/2002/07/secext}UsernameToken',
        xsd.ComplexType([
            xsd.Element('{http://schemas.xmlsoap.org/ws/2002/07/secext}Username', xsd.String()),
            xsd.Element('{http://schemas.xmlsoap.org/ws/2002/07/secext}Password', xsd.String()),
        ])
    )
])
)

还要确保像这样在客户机上放置名称空间

client.set_ns_prefix('wsse', "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")

我花了2天时间,但找到了解决方法。 接受

)

然后像这样将名称空间URL信息添加到所有属性,而不仅仅是组

  header = xsd.Element(
'{http://schemas.xmlsoap.org/ws/2002/07/secext}Security',
xsd.ComplexType([
    xsd.Element(
        '{http://schemas.xmlsoap.org/ws/2002/07/secext}UsernameToken',
        xsd.ComplexType([
            xsd.Element('{http://schemas.xmlsoap.org/ws/2002/07/secext}Username', xsd.String()),
            xsd.Element('{http://schemas.xmlsoap.org/ws/2002/07/secext}Password', xsd.String()),
        ])
    )
])
)

还要确保像这样在客户机上放置名称空间

client.set_ns_prefix('wsse', "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")

你最后用的是什么图书馆?什么对你有用?你最终使用了什么图书馆?什么对你有用?很好的回答,救了我一天。在
ns.py
中,
zzep
对WSSE URI进行了硬编码,此后,由gSOAP构建的SOAP服务器拒绝了这一点-我别无选择,只能自己填充标题。答案很好,节省了我的时间。在
ns.py
中,
zzep
硬编码了WSSE URI,此后,由gSOAP构建的SOAP服务器拒绝了这一点-我别无选择,只能自己填充标头。