Hikmat
Hikmat

Reputation: 460

TypeError in zeep (when both choice elements are returned in response)

I am trying to call "Get_Purchase_Orders" operation in python and it throws below error when response is received

TypeError error in Get_Purchase_Orders : {urn:com.workday/bsvc}Bill_To_Address_ReferenceType() got an unexpected keyword argument 'Address_Reference'. Signature: `({Bill_To_Address_Reference: {urn:com.workday/bsvc}Unique_IdentifierObjectType} | {Address_Reference: {urn:com.workday/bsvc}Address_ReferenceType[]}) Unexpected error:  <class 'TypeError'>

the WSDL file is accessible here

My Findings:

Bill_To_Address_Data has two elements (Bill_To_Address_Reference and Address_Reference) that are mutually exclusive, meaning only one out of two elements are expected (there is choice for Bill_To_Address_Reference Address_Reference and both tags are coming in response ). Sample XML can be seen here.

xml chunk can be seen below as well

<bsvc:Bill_To_Address_Data>
 <!-- You have a CHOICE of the next 2 items at this level -->
 <!-- Optional: -->
 <bsvc:Bill_To_Address_Reference bsvc:Descriptor="string">
    <!-- Zero or more repetitions: -->
    <bsvc:ID bsvc:type="string">string</bsvc:ID>
 </bsvc:Bill_To_Address_Reference>
 <!-- Zero or more repetitions: -->
 <bsvc:Address_Reference>
    <!-- Optional: -->
    <bsvc:ID>string</bsvc:ID>
 </bsvc:Address_Reference>
</bsvc:Bill_To_Address_Data>

below is xsd chunk for above xml

<xsd:complexType name="Bill_To_Address_ReferenceType">
    <xsd:annotation>
    <xsd:documentation>Contains a reference instance or a Address Reference ID for an existing address</xsd:documentation>
    <xsd:appinfo>
        <wd:Validation>
        <wd:Validation_Message>The Provided Bill To Address is Invalid for this Purchase Order</wd:Validation_Message>
        </wd:Validation>
        <wd:Validation>
        <wd:Validation_Message>The Provided Bill To Address is Invalid for this Purchase Order</wd:Validation_Message>
        </wd:Validation>
    </xsd:appinfo>
    </xsd:annotation>
    <xsd:sequence>
    <xsd:choice>
        <xsd:element name="Bill_To_Address_Reference" type="wd:Unique_IdentifierObjectType" minOccurs="0">
        <xsd:annotation>
            <xsd:documentation>Reference to an existing Ship-To address.</xsd:documentation>
        </xsd:annotation>
        </xsd:element>
        <xsd:element name="Address_Reference" type="wd:Address_ReferenceType" minOccurs="0" maxOccurs="unbounded">
        <xsd:annotation>
            <xsd:documentation>Address Reference ID</xsd:documentation>
        </xsd:annotation>
        </xsd:element>
    </xsd:choice>
    </xsd:sequence>
</xsd:complexType>

I confirmed this in oxygen when validating XML against the XSD in WSDL or can be accessed here

Now what I want is to ignore this error and parse the response in python using zeep. Any help will be highly appreciated.

Upvotes: 0

Views: 592

Answers (1)

kimbert
kimbert

Reputation: 2422

Your choices are:

  1. Modify the WSDL (the XML schema part) so that both tags are allowed in the same request
  2. Find a setting in Zeep that allows you to switch off XSD validation
  3. Stop using Zeep, and find another tool that allows you to parse a request without validating against the WSDL

Option 1 is best because WSDL is supposed to be a contract between the service and its callers. If you don't validate then the value of using WSDL is greatly reduced.

Upvotes: 1

Related Questions