update syntax to get headers
This commit is contained in:
Jonathan Lin 2022-03-28 13:14:21 -04:00
Родитель 34cc663d64
Коммит 0b09d9c1a4
1 изменённых файлов: 2 добавлений и 4 удалений

Просмотреть файл

@ -4,6 +4,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from http.client import HTTPMessage
import subprocess
import json
import os
@ -28,10 +29,7 @@ from SystemConfiguration import SCDynamicStoreCopyConsoleUser
def downloader(url, file_path):
download = urllib.request.urlopen(url)
meta = download.info()
if hasattr(meta.headers, 'getheaders'):
file_size = int(meta.getheaders("Content-Length")[0])
else:
file_size = int(meta.get_header("Content-Length")[0])
file_size = int(meta.get("Content-Length")[0])
print("%s is %s bytes." % (file_path, file_size))
with open(file_path, 'wb') as code:
chunk_size = 8192