-->

Python SOAP WSDL works in SOAPpy but not ZSI or ze

2019-08-21 03:08发布

问题:

I need a python SOAP library that can handle multipart attachments. My understanding is that this is not supported by SOAPpy or suds but that it is supported by ZSI and zeep. However, while SOAPpy works just fine with the WSDL file that I need to use, ZSI and zeep give me errors. Here is the WSDL file: http://nva1wss.webex.com/nbr/services/NBRStorageService?wsdl. I opened the file in SoapUI and used the "Check WSI Compliance" option and it passed all of the checks.

Here are my errors:

zeep.exceptions.NamespaceError: Unable to resolve type {NBRStorageService}DataHandler. No schema available for the namespace u'NBRStorageService'.

ZSI.generate.WsdlGeneratorError: failed to find import for schema "NBRStorageService"possibly missing @schemaLocation attribute.

----Updated Info----

Based on the verbose output from zeep I believe that the problem with the WSDL is that it uses a data type that zeep is unable to resolve in the schema document at http://schemas.xmlsoap.org/soap/encoding/. Here is the data type definition in the WSDL:

<wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="https://nva1wss.webex.com/nbr/services/NBRStorageService">
        <import namespace="NBRStorageService"/>
        <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
        <complexType name="ArrayOf_tns1_DataHandler">
            <complexContent>
                <restriction base="soapenc:Array">
                    <attribute ref="soapenc:arrayType"
                    wsdl:arrayType="tns1:DataHandler[]"/>
                </restriction>
            </complexContent>
        </complexType>
    </schema>
</wsdl:types>

This WSDL appears to have been generated with Apache Axis 1.4.

Any ideas on how to work around this? Or if anyone has any specific recommendations for server-side changes, I cannot make them, but I can certainly communicate them to the developers who handle the server.

Thank you!

回答1:

Okay. I fixed it!

So, I did some digging, and I found that this is a common problem with Axis generated WSDL’s. The DataHandler type is not supposed to be in the tns1 namespace. It is supposed to be in the apachesoap namespace. So, I changed the namespace in the WSDL, and it still did not work.

So, I did some more digging, and I found that “DataHandler is a platform-specific type that no platform other than Axis is going to understand,” and that the workaround is to change it to a type of byte.

So, here is the section of the WSDL that I have modified locally and is working now:

<wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="https://nva1wss.webex.com/nbr/services/NBRStorageService">
        <import namespace="NBRStorageService"/>
        <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
        <complexType name="ArrayOf_tns1_DataHandler">
            <complexContent>
                <restriction base="soapenc:Array">
                    <attribute ref="soapenc:arrayType"
                    wsdl:arrayType="soapenc:byte[]"/>
                </restriction>
            </complexContent>
        </complexType>
    </schema>
</wsdl:types>

And, BOOM! It works! I am now able to download and handle attachments as described here: http://docs.python-zeep.org/en/master/attachments.html