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:
parent
2fdb8e7f90
commit
1963e506ec
1 changed files with 5 additions and 3 deletions
|
@ -149,7 +149,7 @@ import time
|
|||
import binascii
|
||||
import codecs
|
||||
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+
|
||||
from shlex import quote
|
||||
|
@ -803,12 +803,14 @@ def main():
|
|||
# If download fails, raise a proper exception
|
||||
if rsp is None:
|
||||
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
|
||||
while True:
|
||||
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
|
||||
|
||||
f.write(data)
|
||||
|
|
Loading…
Reference in a new issue