mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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.
This commit is contained in:
parent
605156c904
commit
ef6b437d0d
1 changed files with 3 additions and 0 deletions
|
@ -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…
Reference in a new issue