I got XML element:
<xs:element name="Files" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attribute name="id" type="xs:anyURI" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
I need to create a dictionary request_data
, that I will pass to the Client from zeep
library, and it will handle creating SOAP envelope inserting data from request_data
accordingly to .wsdl
.
The problem is with extending base64Binary
type. I don't know how to represent that in a dictionary.
I tried passing it under multiple key names, f.e:
request_data = {
# other_data,
"Files": [
{
"base64Binary": encoded_file,
"id": "123"
},
]
}
But whatever key name, I pass it always results with error:
TypeError: Files() got an unexpected keyword argument 'base64Binary'. Signature: `xsd:base64Binary, id: xsd:anyURI`
Is there any possibility to create base64Binary
type extension as a dictionary?
In Zeep, you should pass the base64 content directly as the value for the Files entry in the dictionary. The attributes of the complex type (like id) should be included alongside the base64 content.
request_data = {
# other_data,
"Files": [
{
"_value_1": encoded_file, # The base64Binary content goes here
"id": "123", # The attribute defined in the XML
}
]
}
_value_1: This is a special key used by Zeep for simple content in complex types. When a complex type extends a simple type, Zeep expects the value of the simple type to be passed using the _value_1 key.
id: This is the attribute specified in the XML schema.