python - SOAPpy - 如何传递安全 header ?

标签 python web-services apache-axis webservice-client soappy

我目前正在为使用 Axis2 WS-Security 的应用程序开发 python 网络服务

简化后的相关代码是

from SOAPpy import SOAPProxy
from SOAPpy import WSDL

file = 'path/to/my/file?wsdl'
server = WSDL.Proxy(file)

server.foo(bar)

这样做时我得到:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\SOAPpy\Client.py", line 471, in __call__
    return self.__r_call(*args, **kw)
  File "C:\Python27\lib\site-packages\SOAPpy\Client.py", line 493, in __r_call
    self.__hd, self.__ma)
  File "C:\Python27\lib\site-packages\SOAPpy\Client.py", line 407, in __call
    raise p
SOAPpy.Types.faultType: <Fault soapenv:Client: WSDoAllReceiver: Incoming message
 does not contain required Security header: >

阅读 axis2 WS-security 的文档和提供 web 服务的应用程序我猜它要求我进行用户 token 身份验证,例如

<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-12468716">
<wsu:Created>
2008-06-23T13:17:13.841Z
</wsu:Created>
<wsu:Expires>
2008-06-23T13:22:13.841Z
</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-31571602">
<wsse:Username>
alice
</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
bobPW
</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>

当做一个请求时,所以问:我怎样才能将这个附加到 SOAPpy 请求中?

最佳答案

查看有关向肥皂请求添加 header 的文档 (https://svn.origo.ethz.ch/playmobil/trunk/contrib/pywebsvcs/SOAPpy/docs/UsingHeaders.txt)。通过这种方式,您可以将自己的自定义 header 添加到任何请求。

希望对你有帮助

关于python - SOAPpy - 如何传递安全 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6301413/

相关文章:

.net - WCF 日期时间偏移兼容性

.net - 如何在构建时自动更新 Web 引用?

java - 如何组织Web服务,以便开发人员可以轻松找到它们?

eclipse - 带有eclipse、tomcat6、axis2问题的Web服务

tomcat - 我们可以将 axis2 文件夹放在另一个文件夹下,而不是直接将它放在 webapps 下吗?

python - 检查文件是否存在于 Python 2.7 中

python - 使用Python删除Excel行

python - 在不知道列和行的情况下替换 Pandas Dataframe 中的某些值

Java Web 服务并发问题

python - 在 Mac 上使用 matplotlib for Python 2.7