【问题标题】:How do I add a factory created type as a header in suds?如何在 suds 中添加工厂创建的类型作为标题?
【发布时间】:2010-11-05 16:36:44
【问题描述】:

我的设置似乎无法产生泡沫。在我可以使用 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'""'}
...

我在标头中的任何地方都没有看到上下文,并且服务器错误地指出没有远程用户集。

我做错了什么?

【问题讨论】:

    标签: python soap header suds


    【解决方案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)
    

    即是上下文对象的身份验证部分吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-11
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      • 2020-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多