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

Fix crash in py3: 'TypeError: a bytes-like object is required, not 'str' (#37504)

* Fix crash in py3: 'TypeError: a bytes-like object is required, not 'str'

Fixes #37387

* Review applied https://github.com/ansible/ansible/pull/37504#pullrequestreview-104799823
This commit is contained in:
alu 2018-03-21 06:33:14 +09:00 committed by Toshio Kuratomi
parent 8c4f349743
commit b7aa41b9b9

View file

@ -141,6 +141,7 @@ import re
import tempfile
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_bytes
def lineDict(line):
@ -321,7 +322,7 @@ def write_changes(module, lines, dest):
tmpfd, tmpfile = tempfile.mkstemp()
f = os.fdopen(tmpfd, 'wb')
f.writelines(lines)
f.writelines(to_bytes(lines, errors='surrogate_or_strict'))
f.close()
module.atomic_move(tmpfile, os.path.realpath(dest))