Fix TypeError when using old simplejson lib.

On some very old simplejson does not support the 'encoding' and give
following exception:

   TypeError: __init__() got an unexpected keyword argument 'encoding'

This fix runs json.dump with no encoding key (such as before #a023cb) on
TypeError exception only.
pull/6679/head
Sébastien Gross 11 years ago
parent 605156c904
commit ef6b437d0d

@ -884,6 +884,9 @@ class AnsibleModule(object):
for encoding in ("utf-8", "latin-1", "unicode_escape"):
try:
return json.dumps(data, encoding=encoding)
# Old systems using simplejson module does not support encoding keyword.
except TypeError, e:
return json.dumps(data)
except UnicodeDecodeError, e:
continue
self.fail_json(msg='Invalid unicode encoding encountered')

Loading…
Cancel
Save