3

Because of the remote WSDL service, the request generated by the zeep library is considered invalid. For this reason, product images are not loading. However, what it will do is use the urls in the array.

The problem here is, the XML output produced by the zeep library is as follows:

<ns1:Images>
    <ns2:string xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
        https://www.example.com/variant_image.png
    </ns2:string>
    <ns3:string xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
        https://www.example.com/variant_image2.png
    </ns3:string>
    <ns4:string xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
        https://www.example.com/variant_image3.png
    </ns4:string>
</ns1:Images>

Here is the method I used to generate this XML:

from zeep import Client
from zeep.transports import Transport

transport = Transport()
client = Client(service_url, 
                transport=transport,
                strict=False)


images = client.get_type("ns4:ArrayOfstring")()
local_images = [
    "https://www.example.com/variant_image.png",
    "https://www.example.com/variant_image2.png",
    "https://www.example.com/variant_image3.png",
]

for image in local_images:
    images["string"].append(image)

However, the XML requested by the WSDL service to receive the images had to be as follows:

<s:Images xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
    <a:string>https://www.example.com/variant_image.png</ns2:string>
    <a:string>https://www.example.com/variant_image2.png</ns2:string>
    <a:string>https://www.example.com/variant_image3.png</ns2:string>
</s:Images>

As you can see in the XML above, items namespace declared in array definition and the all items are using the same namespace. The name space of the array also different than generated one.

In this case, I need to set the namespace specifier as requested in the part of the XML generated when making a request with zeep and have the same namespace used for each item.

Is there any possibility to do this?

Sencer H.
  • 1,201
  • 1
  • 13
  • 35

1 Answers1

0

It turned out that appending strings like this:

images["string"].append(image)

ends up with this XML:

<ns1:Images>
    <ns2:string xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
        https://www.example.com/variant_image.png
    </ns2:string>
    <ns3:string xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
        https://www.example.com/variant_image2.png
    </ns3:string>
    <ns4:string xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
        https://www.example.com/variant_image3.png
    </ns4:string>
</ns1:Images>

The solution I figured out is putting an list of strings directly to ArrayOfstring, instead appending it to one by one:

image_urls = list()
for image in local_images:
    image_urls.append(image)
images["string"] = image_urls
Sencer H.
  • 1,201
  • 1
  • 13
  • 35