如何使用泡沫添加新对象?

发布于 2024-09-03 01:53:09 字数 1839 浏览 7 评论 0原文

我正在尝试使用泡沫,但到目前为止还没有成功地解决这个问题。

这应该是我需要实现的原始肥皂消息:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:api="http://api.service.apimember.soapservice.com/">
    <soapenv:Header/>
    <soapenv:Body>
        <api:insertOrUpdateMemberByObj>
        <token>t67GFCygjhkjyUy8y9hkjhlkjhuii</token>
             <member>
                 <dynContent>
                     <entry>
                         <key>FIRSTNAME</key>
                         <value>hhhhbbbbb</value>
                     </entry>
                 </dynContent>
                 <email>[email protected]</email>
             </member>
         </api:insertOrUpdateMemberByObj>
     </soapenv:Body>
</soapenv:Envelope>

所以我使用 suds 来创建成员对象:

member = client.factory.create('member')

产生:

(apiMember){
   attributes =
      (attributes){
         entry[] = <empty>
      }
 }

如何准确地附加一个“条目”?

我尝试了这个:

member.attributes.entry.append({'key':'FIRSTNAME','value':'test'})

它产生this:

(apiMember){
   attributes =
      (attributes){
         entry[] =
            {
               value = "test"
               key = "FIRSTNAME"
            },
      }
 }

但是,我真正需要的是:

(apiMember){
   attributes =
      (attributes){
         entry[] =
            (entry) {
               value = "test"
               key = "FIRSTNAME"
            },
      }
 }

我如何实现这一点?

I'm trying to use suds but have so far been unsuccessful at figuring this out.

This is supposed to be the raw soap message that I need to achieve:

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:api="http://api.service.apimember.soapservice.com/">
    <soapenv:Header/>
    <soapenv:Body>
        <api:insertOrUpdateMemberByObj>
        <token>t67GFCygjhkjyUy8y9hkjhlkjhuii</token>
             <member>
                 <dynContent>
                     <entry>
                         <key>FIRSTNAME</key>
                         <value>hhhhbbbbb</value>
                     </entry>
                 </dynContent>
                 <email>[email protected]</email>
             </member>
         </api:insertOrUpdateMemberByObj>
     </soapenv:Body>
</soapenv:Envelope>

So I use suds to create the member object:

member = client.factory.create('member')

produces:

(apiMember){
   attributes =
      (attributes){
         entry[] = <empty>
      }
 }

How exactly do I append an 'entry'?

I tried this:

member.attributes.entry.append({'key':'FIRSTNAME','value':'test'})

which produces this:

(apiMember){
   attributes =
      (attributes){
         entry[] =
            {
               value = "test"
               key = "FIRSTNAME"
            },
      }
 }

However, what I actually need is:

(apiMember){
   attributes =
      (attributes){
         entry[] =
            (entry) {
               value = "test"
               key = "FIRSTNAME"
            },
      }
 }

How do I achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦巷 2024-09-10 01:53:09

您仍然需要使用工厂创建对象:

member = client.factory.create('member')
entry = client.factory.create('member.attributes.entry')
entry.key = 'FIRSTNAME';
entry.value = 'test';
member.attributes.entry.append(entry)

you still need to create object with factory:

member = client.factory.create('member')
entry = client.factory.create('member.attributes.entry')
entry.key = 'FIRSTNAME';
entry.value = 'test';
member.attributes.entry.append(entry)
油饼 2024-09-10 01:53:09

member = client.factory.create('member')
entry = client.factory.create('attributes')
entry.key="FIRSTNAME"
entry.value="test"
member.attributes.entry.append(entry)

这确实取决于定义 SOAP 连接的 WSDL,但 attributes 也应该是 WSDL 中定义的结构

Off the top of my head (all the suds stuff is at work at the moment)

member = client.factory.create('member')
entry = client.factory.create('attributes')
entry.key="FIRSTNAME"
entry.value="test"
member.attributes.entry.append(entry)

This does depend on the WSDL that defines your SOAP connection, but attributes should also be a structure defined in the WSDL.

谎言 2024-09-10 01:53:09

这就是当我尝试创建“条目”时发生的情况:

>>> member = client.factory.create('member')
>>> entry = client.factory.create('attributes')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build\bdist.win32\egg\suds\client.py", line 231, in create
suds.TypeNotFound: Type not found: 'attributes'
>>>

This is what happens when i try to create "entry":

>>> member = client.factory.create('member')
>>> entry = client.factory.create('attributes')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build\bdist.win32\egg\suds\client.py", line 231, in create
suds.TypeNotFound: Type not found: 'attributes'
>>>
2024-09-10 01:53:09

试试这个,使用我的 WSDL 可以实现类似的效果。

member.attributes.entry = {'key':'FIRSTNAME','value':'test'}

正如 simon 所说,这确实取决于您的 WSDL。

Try this, a similar thing worked using my WSDL.

member.attributes.entry = {'key':'FIRSTNAME','value':'test'}

As simon said, it does depend on your WSDL.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文