When using jsonify in modules, try several unicode encoding for dumps()
Fixes #4821
This commit is contained in:
parent
ce0b1a8a96
commit
a023cbce14
1 changed files with 6 additions and 1 deletions
|
@ -840,7 +840,12 @@ class AnsibleModule(object):
|
|||
self.fail_json(msg='Boolean %s not in either boolean list' % arg)
|
||||
|
||||
def jsonify(self, data):
|
||||
return json.dumps(data)
|
||||
for encoding in ("utf-8", "latin-1", "unicode_escape"):
|
||||
try:
|
||||
return json.dumps(data, encoding=encoding)
|
||||
except UnicodeDecodeError, e:
|
||||
continue
|
||||
self.fail_json(msg='Invalid unicode encoding encountered')
|
||||
|
||||
def from_json(self, data):
|
||||
return json.loads(data)
|
||||
|
|
Loading…
Reference in a new issue