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

Open file in binary mode for python3

This commit is contained in:
Paul Montero 2017-03-05 23:52:32 -05:00 committed by Toshio Kuratomi
parent 2fdb8e7f90
commit 1963e506ec

View file

@ -149,7 +149,7 @@ import time
import binascii import binascii
import codecs import codecs
from zipfile import ZipFile, BadZipfile from zipfile import ZipFile, BadZipfile
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_bytes, to_text
try: # python 3.3+ try: # python 3.3+
from shlex import quote from shlex import quote
@ -803,12 +803,14 @@ def main():
# If download fails, raise a proper exception # If download fails, raise a proper exception
if rsp is None: if rsp is None:
raise Exception(info['msg']) raise Exception(info['msg'])
f = open(package, 'w') # open in binary mode for python3
f = open(package, 'wb')
# Read 1kb at a time to save on ram # Read 1kb at a time to save on ram
while True: while True:
data = rsp.read(BUFSIZE) data = rsp.read(BUFSIZE)
data = to_bytes(data, errors='surrogate_or_strict')
if data == "": if len(data) < 1:
break # End of file, break while loop break # End of file, break while loop
f.write(data) f.write(data)