字符串类型不接受集合作为值

问题描述 投票:0回答:2

我收到这个错误:

字符串类型不接受集合作为值

当我尝试运行这段代码时:

fetch_data = client.get_type('ns0:ArrayOfString')
    fetch = fetch_data ([
        "Unique_Key",
        "First_Name",
        "Last_Name",
        "Address1",
        "Address2",
        "City",
        "State",
        "Zip",
        "Source",
        "Grad_Year",
        "Email_Address",
        "Submission_Type",
        "Print_Response_Date",
        "Date_Fulfillment_Complete"])

在它的正上方,我有这个代码部分可以正常工作:

search_criteria = client.get_type('ns0:Ext_Webservice_ComplexType_SearchCriteria')
    search = search_criteria ([
        {
            "column_key": "Submission_Type",
            "operand": "<>",
            "value": "ELECTRONIC",
            "next": "and",
            "prefix": "",
            "suffix": ""
        },
        {
            "column_key": "Date_Fulfillment_Complete",
            "operand": "IS NULL",
            "value": "",
            "next": "",
            "prefix": "",
            "suffix": ""
        }
    ])

虽然我知道他们使用的是两种不同的类型,但我对为什么一种有效而另一种无效感到困惑。我认为 ArrayOfString 会接受一个字符串数组,但我可能想错了。不可否认,这是我很长一段时间以来(现在将近 8 年)的第一个 python 项目,所以我非常生疏。只是想知道从这里去哪里。其他答案没有帮助。我曾尝试将值添加为命名参数,也曾尝试简单地使用 append 函数。我愿意打赌答案可能是显而易见的,但我希望一些橡皮鸭能帮助我解决这个问题。

提前致谢!

编辑:运行 mzeep 命令给我返回:

ns0:ArrayOfExt_webservice_complextype_person(item:ns0:Ext_Webservice_ComplexType_Person[])

ns0:ArrayOfExt_webservice_complextype_recordwithkey(item:ns0:Ext_Webservice_ComplexType_RecordWithKey[])

ns0:ArrayOfExt_webservice_complextype_recordwithoutkey(item:ns0:Ext_Webservice_ComplexType_RecordWithoutKey[])

ns0:ArrayOfExt_webservice_complextype_searchcriteria(item:ns0:Ext_Webservice_ComplexType_SearchCriteria[])

ns0:ArrayOfInt(item: xsd:int[])

ns0:ArrayOfString(item: xsd:string[])

*Along with several others that I've removed for readability.

 
python soap zeep
2个回答
1
投票

基于那个 WSDL,这段代码对我有用:

from zeep import Client

client = Client('https://ws.185red.com/wsdl/forms') 

fetch_type = client.get_type('ns0:ArrayOfString')
fetch = fetch_type([
    "Unique_Key",
    "First_Name",
    "Last_Name",
    "Address1",
    "Address2",
    "City",
    "State",
    "Zip",
    "Source",
    "Grad_Year",
    "Email_Address",
    "Submission_Type",
    "Print_Response_Date",
    "Date_Fulfillment_Complete"])

criteria_type = client.get_type('ns0:ArrayOfExt_webservice_complextype_searchcriteria')
criteria = criteria_type([
    {
        "column_key": "Submission_Type",
        "operand": "<>",
        "value": "ELECTRONIC",
        "next": "and",
        "prefix": "",
        "suffix": ""
    },
    {
        "column_key": "Date_Fulfillment_Complete",
        "operand": "IS NULL",
        "value": "",
        "next": "",
        "prefix": "",
        "suffix": ""
    }
])

client.service.FetchData(0, criteria, fetch)

我得到一个“zeep.exceptions.Fault: Not Allowed. Message: Not logged in.”,这是有道理的,因为我没有先授权,我只是直接发送一条消息,但是调用使它成为服务,它看起来格式正确:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Body>
    <ns0:FetchData xmlns:ns0="https://ws.185red.com">
      <formId>0</formId>
      <criteria>
        <item>
          <column_key>Submission_Type</column_key>
          <operand>&lt;&gt;</operand>
          <value>ELECTRONIC</value>
          <next>and</next>
          <prefix></prefix>
          <suffix></suffix>
        </item>
        <item>
          <column_key>Date_Fulfillment_Complete</column_key>
          <operand>IS NULL</operand>
          <value></value>
          <next></next>
          <prefix></prefix>
          <suffix></suffix>
        </item>
      </criteria>
      <keysToFetch>
        <item>Unique_Key</item>
        <item>First_Name</item>
        <item>Last_Name</item>
        <item>Address1</item>
        <item>Address2</item>
        <item>City</item>
        <item>State</item>
        <item>Zip</item>
        <item>Source</item>
        <item>Grad_Year</item>
        <item>Email_Address</item>
        <item>Submission_Type</item>
        <item>Print_Response_Date</item>
        <item>Date_Fulfillment_Complete</item>
      </keysToFetch>
    </ns0:FetchData>
  </soap-env:Body>
</soap-env:Envelope>

你能试试我的代码吗?


0
投票

我遇到了同样的错误,我能够解决它。不幸的是,我无法在网上找到答案。

以下是您的代码出现问题的地方: fetch_type = client.get_type('ns0:ArrayOfString') 尝试以下: fetch_type = client.get_type({'ns0': ArrayOfString})

基本上您缺少 {}。此外,它取决于 API 的提供者。如果仍然出现错误,请尝试传递不带键的值和以逗号分隔的 {}

例如假设你的值为 1 和 2: fetch_type = client.get_type(1,2)

© www.soinside.com 2019 - 2024. All rights reserved.