1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

When using jsonify in modules, try several unicode encoding for dumps()

Fixes #4821
This commit is contained in:
James Cammarata 2014-02-11 14:19:00 -06:00
parent ce0b1a8a96
commit a023cbce14

View file

@ -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)