Created
December 11, 2015 13:39
-
-
Save harunyasar/25db367e2fbf57f55f56 to your computer and use it in GitHub Desktop.
Convert SUDS response object to dict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from suds.sudsobject import asdict | |
def recursive_asdict(d): | |
"""Convert Suds object into serializable format.""" | |
out = {} | |
for k, v in asdict(d).iteritems(): | |
if hasattr(v, '__keylist__'): | |
out[k] = recursive_asdict(v) | |
elif isinstance(v, list): | |
out[k] = [] | |
for item in v: | |
if hasattr(item, '__keylist__'): | |
out[k].append(recursive_asdict(item)) | |
else: | |
out[k].append(item) | |
else: | |
out[k] = v | |
return out | |
def suds_to_json(data): | |
return json.dumps(recursive_asdict(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice,
but what about the reverse operation?