Download remote apt deb file in bytes mode in Python 2 and 3
Fixes #19710
This commit is contained in:
parent
9f0b354023
commit
8ec28a2ba4
1 changed files with 5 additions and 3 deletions
|
@ -234,7 +234,7 @@ import time
|
|||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils._text import to_bytes, to_native
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
|
||||
# APT related constants
|
||||
|
@ -716,12 +716,14 @@ def download(module, deb):
|
|||
|
||||
try:
|
||||
rsp, info = fetch_url(module, deb)
|
||||
f = open(package, 'w')
|
||||
# Ensure file is open in binary mode for Python 3
|
||||
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