2010-11-05 18 views
0

我似乎無法使用我的設置起泡。在使用API​​中的任何函數之前,我必須先設置一個遠程用戶的上下文。我試圖做的是這樣的:如何添加工廠創建的類型作爲泡沫中的標題?

client = Client(url, username=userid, password=password) 
apiContext = client.factory.create("apiCallContext")  # This is listed in the types 
apiContext.remoteUser = "serviceAccount"     # when I print the client 

client.set_options(soapheaders=apiContext) 
client.service.getActiveIPs() 

在整個過程中,一切似乎變得正確創建(如果我打印的客戶,我看到所有的功能和類型,如果我打印APICONTEXT,我看到的一切設置正確的),但頭不實際上似乎越來越設置:

... 
DEBUG:suds.client:sending to ($URL) message: 
    <?xml version="1.0" encoding="UTF-8"?> 
    <SOAP-ENV:Envelope xmlns:ns0=$NS 
        xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
    <SOAP-ENV:Header/> 
    <ns1:Body> 
    <ns0:getActiveIPs/> 
    </ns1:Body> 
    </SOAP-ENV:Envelope> 
DEBUG:suds.client:headers = {'SOAPAction': u'""', 
          'Content-Type': 'text/xml; charset=utf-8'} 
DEBUG:suds.transport.http:sending: 
    URL:$URL 
    HEADERS: {'SOAPAction': u'""', 'Content-Type': 'text/xml; charset=utf-8', 
      'Content-type': 'text/xml; charset=utf-8', 'Soapaction': u'""'} 
... 

我沒有看到上下文中的任何地方標題,並且服務器示數了,有沒有遠程用戶組。

我在做什麼錯?

回答

1

不知道你正在使用的web服務的確切規格,我只能冒這個答案的猜測,但頭看起來類似於我以前使用的web服務。你已經嘗試直接創建的元素並將它們傳遞到報頭從而?:

from suds.sax.element import Element 
... 
NS = ('h', SOME_NAMESPACE) 
apiContext = Element('apiContext') 
authcred = Element('authenticationCredential', ns=NS) 
username = Element(userid, ns=NS).setText('USERNAME') 
passw = Element(password, ns=NS).setText('PASSWORD') 
authcred.append(username) 
authcred.append(passw) 
apiContext.append(authcred) 
client.set_options(soapheaders=apiContext) 

即是上下文對象的認證部分?