pythonzeep

Python Zeep- 'Input string was not in a correct format'


I am using zeep to interact with a webservice in Python; I have everything mostly working but am having trouble getting certain fields set. The issue appears to be with the input string, it is attempting to convert it to 'Text' but is failing. I am a bit lost and do not know how to accomplish this, I've had no luck so far. I'm assuming I have to do some sort of conversion but I am not sure how to do this.

For context, this is what I am trying to set. The field(Voucher ID in this case) is found but the FieldValue is not formatted correctly. Here is a rundown of that code.

        #Set fields
        voucher_id.FieldId = 15   #Voucher ID
        voucher_id.FieldValue = "test"

        #Array
        field_array =  factory.ArrayOfFieldWithValue()
        field_array['FieldWithValue'].append(voucher_id)

        #Call service function to add document info, which causes the exception

And here are the exception messages.

      #Post envelope

<faultstring>Server was unable to read request. ---&gt; There is an error in XML document (2, 253). ---&gt; Input string was not in a correct format.</faultstring>
      <detail>
        <ExceptionType>System.InvalidOperationException</ExceptionType>
        <ExceptionMessage>System.InvalidOperationException: There is an error in XML document (2, 253). ---&gt; System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&amp; number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read135_SetMetadata()
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)




      #Response envelope

      <faultstring>Server was unable to process request. ---&gt; Voucher ID cannot be converted to Text</faultstring>
      <detail>
        <ExceptionType>FileHold.Common.ArgumentException</ExceptionType>
        <ExceptionMessage>FileHold.Common.ArgumentException: Voucher ID cannot be converted to Text
   at FileHold.LibraryManager.FieldDefinition.Validate(Object value, Int32 schemaId) in c:\Builds\5\FileHold\FileHold16\src\FileHold\LibraryManager\Code\FieldDefinition.cs:line 269
   at FileHold.LibraryManager.DocumentManager.MergeAndValidateValues(FieldWithValue[] fieldsWithValues, FieldDefinition[] currentFieldDefinitions, DocumentData&amp; currentDocumentData, Boolean canEditReadOnly, Boolean initializeMode, List`1&amp; changedFieldsIds) in c:\Builds\5\FileHold\FileHold16\src\FileHold\LibraryManager\DocumentManager.asmx.cs:line 135
   at FileHold.LibraryManager.DocumentManager.AddDocumentInfo(DocumentInfo info, Database database, DbTransaction transaction) in c:\Builds\5\FileHold\FileHold16\src\FileHold\LibraryManager\DocumentManager.asmx.cs:line 1134
   at FileHold.LibraryManager.DocumentManager.AddDocumentInfo(DocumentInfo info) in c:\Builds\5\FileHold\FileHold16\src\FileHold\LibraryManager\DocumentManager.asmx.cs:line 873</ExceptionMessage>
        <ErrorCode>InvalidFormat</ErrorCode>
      </detail>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>


I have tried formatting the FieldValue in a couple of other basic ways but always receive the same error.


Solution

  • Solved by using zeep.xsd.AnyObject to transform Python type to xsd type.

    voucher_id.FieldValue = zeep.xsd.AnyObject(zeep.xsd.String(), 'zeep_test')