Dictionary returns in ZSI
- Comments:
- here.
For my day job, I am developing a SOAP server in python. I have been using ZSI as a framework, and it is very good. It will, with mod_python, allow you to build a complete application in python (and even without mod_python you can have it as a standalone process). One of the touted features is easy return of lists and dictionaries, without having to declare ComplexTypes classes.
However, it doesn’t quite work. And the not-working-bit is really odd.
If you return a dict, such as the following:
|
|
Then ZSI creates a SOAP response like:
|
|
But, if you return a dictionary with values that happen to be the same, as I did with my boilerplate code:
|
|
Then it fails. The second and any other instance of any dict key where the value has already been used by another key is empty, and the wrong type:
|
|
This can be overcome with liberal use of classes (or subclasses, since most of the time I am returning dicts or lists). It is a bit of a pain in the arse, though. I’ve filed a bug report. And stopped using ZSI. If I found this bug this fast, then I don’t want to know how many more there are. It’s just easier to convert the XML to python objects and back again, and package it up to look like a SOAP request. Which is kind of what SOAP does anyway.