@@ -72,36 +72,41 @@ def get_url() -> str:
72
72
73
73
def download_zip (url : str ) -> BytesIO :
74
74
"""Download data from url."""
75
- logger .warning ('start chromium download.\n '
75
+ logger .warning ('Starting Chromium download. '
76
76
'Download may take a few minutes.' )
77
77
78
- # disable warnings so that we don't need a cert.
79
- # see https://urllib3.readthedocs.io/en/latest/advanced-usage.html for more
80
- urllib3 .disable_warnings ()
78
+ # Uncomment the statement below to disable HTTPS warnings and allow
79
+ # download without certificate verification. This is *strongly* as it
80
+ # opens the code to man-in-the-middle (and other) vulnerabilities; see
81
+ # https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
82
+ # for more.
83
+ # urllib3.disable_warnings()
81
84
82
85
with urllib3 .PoolManager () as http :
83
86
# Get data from url.
84
87
# set preload_content=False means using stream later.
85
- data = http .request ('GET' , url , preload_content = False )
86
-
87
- try :
88
- total_length = int (data .headers ['content-length' ])
89
- except (KeyError , ValueError , AttributeError ):
90
- total_length = 0
91
-
92
- process_bar = tqdm (
93
- total = total_length ,
94
- file = os .devnull if NO_PROGRESS_BAR else None ,
95
- )
88
+ r = http .request ('GET' , url , preload_content = False )
89
+ if r .status >= 400 :
90
+ raise OSError (f'Chromium downloadable not found at { url } : '
91
+ f'Received { r .data .decode ()} .\n ' )
96
92
97
93
# 10 * 1024
98
94
_data = BytesIO ()
99
- for chunk in data .stream (10240 ):
100
- _data .write (chunk )
101
- process_bar .update (len (chunk ))
102
- process_bar .close ()
103
-
104
- logger .warning ('\n chromium download done.' )
95
+ if NO_PROGRESS_BAR :
96
+ for chunk in r .stream (10240 ):
97
+ _data .write (chunk )
98
+ else :
99
+ try :
100
+ total_length = int (r .headers ['content-length' ])
101
+ except (KeyError , ValueError , AttributeError ):
102
+ total_length = 0
103
+ process_bar = tqdm (total = total_length )
104
+ for chunk in r .stream (10240 ):
105
+ _data .write (chunk )
106
+ process_bar .update (len (chunk ))
107
+ process_bar .close ()
108
+
109
+ logger .warning ('\n Chromium download done.' )
105
110
return _data
106
111
107
112
0 commit comments