Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows dependency downloader: replaced requests with urllib #1493

Merged
merged 2 commits into from Nov 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions buildconfig/download_win_prebuilt.py
Expand Up @@ -14,7 +14,10 @@ def download_sha1_unzip(url, checksum, save_to_directory, unzip=True):
Does not download again if the file is there.
Does not unzip again if the file is there.
"""
import requests
try:
import urllib.request as urllib
except ImportError:
import urllib2 as urllib
import hashlib
import zipfile

Expand All @@ -31,14 +34,17 @@ def download_sha1_unzip(url, checksum, save_to_directory, unzip=True):
print("Skipping download url:%s: save_to:%s:" % (url, save_to))
else:
print("Downloading...", url, checksum)
response = requests.get(url)
cont_checksum = hashlib.sha1(response.content).hexdigest()
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, '
'like Gecko) Chrome/35.0.1916.47 Safari/537.36'}
request = urllib.Request(url, headers=headers)
response = urllib.urlopen(request).read()
cont_checksum = hashlib.sha1(response).hexdigest()
if checksum != cont_checksum:
raise ValueError(
'url:%s should have checksum:%s: Has:%s: ' % (url, checksum, cont_checksum)
)
with open(save_to, 'wb') as f:
f.write(response.content)
f.write(response)

if unzip and filename.endswith('.zip'):
print("Unzipping :%s:" % save_to)
Expand Down