2011-06-10 23 views
2

即時通訊目前正在開發一個Python Web服務的,它使用的Axis2應用的WS-SecuritySOAPpy - 如何傳遞安全標題?

簡化相關代碼

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服務的應用程序im猜測其請求我的用戶令牌身份驗證,如

<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請求?

回答

1

查看關於向soapy請求添加標頭的文檔(https://svn.origo.ethz.ch/playmobil/trunk/contrib/pywebsvcs/SOAPpy/docs/UsingHeaders.txt)。這樣您可以將自己的自定義標題添加到任何請求。

希望這會有所幫助