首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >集成<item>列表的Python zeep问题

集成<item>列表的Python zeep问题
EN

Stack Overflow用户
提问于 2020-04-16 11:28:02
回答 1查看 535关注 0票数 0

我有一个SOAP服务,它是这样调用的:

代码语言:javascript
运行
复制
import zeep
import random
import string
from lxml import etree as ET

class Hostopia_SOAP():

    def __init__(self, user, password, wsdl):
        self.wsdl = wsdl
        self.cred = self.set_cred(user, password)
        self.sc = zeep.Client(self.wsdl)

    def set_cred(self, user, password):

        return {'username' : user, 'password' : password}

    def get_all_domains(self, start=0, package=None, status=None, externalid=None, rserverid=None, 
            accountid=None, customernumber=None):

         return self.sc.service.getAllDomains(self.cred,str(start),[ ])

xml结果如下所示:

代码语言:javascript
运行
复制
<?xml version='1.0' encoding='utf-8'?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Body>
    <ns0:getAllDomains xmlns:ns0="urn:RRAD">
      <primary>
        <username>user</username>
        <password>password</password>
      </primary>
      <startNumber>0</startNumber>
      <conditions/>
    </ns0:getAllDomains>
  </soap-env:Body>
</soap-env:Envelope>

一切都很顺利!

但是,我尝试添加一些条件,例如:

代码语言:javascript
运行
复制
 self.sc.service.getAllDomains(self.cred,str(start),[ 'key1=value' ])

在我的请求中,我得到了这个错误:

代码语言:javascript
运行
复制
Traceback (most recent call last):
  File "z:/No-git/Scripts/HostoSOAP.py", line 286, in <module>
    print(client.debug('getAllDomains', '0', ['status=OK']))
  File "z:/No-git/Scripts/HostoSOAP.py", line 243, in debug
    node = self.sc.create_message(self.sc.service, service, self.cred, *args)
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\client.py", line 139, in create_message
    operation_name, args, kwargs, client=self
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\wsdl\bindings\soap.py", line 68, in _create
    serialized = operation_obj.create(*args, **kwargs)
    return self.input.serialize(*args, **kwargs)
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\wsdl\messages\soap.py", line 74, in serialize
    self.body.render(body, body_value)
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\xsd\elements\element.py", line 231, in render
    self._render_value_item(parent, value, render_path)
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\xsd\elements\element.py", line 255, in _render_value_item
    return self.type.render(node, value, None, render_path)
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\xsd\types\complex.py", line 279, in render
    element.render(parent, element_value, child_path)
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\xsd\elements\indicators.py", line 242, in render
    element.render(parent, element_value, child_path)
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\xsd\elements\element.py", line 231, in render
    self._render_value_item(parent, value, render_path)
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\xsd\elements\element.py", line 255, in _render_value_item
    return self.type.render(node, value, None, render_path)
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\xsd\types\complex.py", line 279, in render
    element.render(parent, element_value, child_path)
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\xsd\elements\indicators.py", line 242, in render
    element.render(parent, element_value, child_path)
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\xsd\elements\any.py", line 126, in render
    self.validate(value, render_path)
  File "F:\dev-tools-plugin\Anaconda3\lib\site-packages\zeep\xsd\elements\any.py", line 184, in validate
    raise exceptions.ValidationError("Missing element for Any")
zeep.exceptions.ValidationError: Missing element for Any

XLM方面如下所示:

代码语言:javascript
运行
复制
<?xml version='1.0' encoding='utf-8'?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Body>
    <ns0:getAllDomains xmlns:ns0="urn:RRAD">
      <primary>
        <username>user</username>
        <password>password</password>
      </primary>
      <startNumber>0</startNumber>
      <conditions>
        <item>key1=value</item>
        <item>key2=value</item>
      <conditions/>
    </ns0:getAllDomains>
  </soap-env:Body>
</soap-env:Envelope>

有人知道怎么集成这个吗?

如果它可以提供帮助,等待类型为(ArrayOfString),包含以下信息:

代码语言:javascript
运行
复制
ArrayOfStrings({urn:RRAD}ArrayOfStrings(_value_1: string[], arrayType: xsd:string, offset: {http://schemas.xmlsoap.org/soap/encoding/}arrayCoordinate, id: xsd:ID, href: xsd:anyURI, _attr_1: {}))

字典:

代码语言:javascript
运行
复制
{'name': 'ArrayOfStrings', '_element': <Group(<zeep.xsd.elements.indicators.Group object at 0x00000265210B5488>)>, '_attributes': [<Attribute(name='arrayType', type=<zeep.xsd.types.builtins.String object at 0x000002652083F7C8>)>, <Attribute(name='offset', type=<zeep.xsd.dynamic_types.arrayCoordinate object at 0x00000265210AF808>)>, <Attribute(name='id', type=<zeep.xsd.types.builtins.ID object at 0x00000265208494C8>)>, <Attribute(name='href', type=<zeep.xsd.types.builtins.AnyURI object at 0x000002652083FFC8>)>, <zeep.xsd.elements.any.AnyAttribute object at 0x00000265210AF248>], '_restriction': None, '_extension': None, '_extension_types': (), 'qname': <lxml.etree.QName object at 0x0000026521133DE0>, '_resolved': <zeep.xsd.dynamic_types.ArrayOfStrings object at 0x00000265210DD148>, 'is_global': True}

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2020-04-16 12:22:52

我认为您可以尝试使用kwargs调用getAllDomains方法,例如:

代码语言:javascript
运行
复制
self.service.getAllDomains(self.cred, startNumber=str(start), conditions=[ 'key1=value' ])
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61242199

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档