2010-11-05 17 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) 

即是上下文对象的认证部分?