From c43b99a02ee0487b54a16701dc7313eca3233ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 10 Jun 2020 13:14:33 +0200 Subject: [PATCH] validity-sensors-initializer: Set referrer and user agent --- validity-sensors-initializer.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/validity-sensors-initializer.py b/validity-sensors-initializer.py index 16ae261..3dbe38f 100644 --- a/validity-sensors-initializer.py +++ b/validity-sensors-initializer.py @@ -42,8 +42,14 @@ class VFS(Enum): DEV_97 = 0x0097 DEFAULT_URIS = { - VFS.DEV_90: 'https://download.lenovo.com/pccbbs/mobiles/n1cgn08w.exe', - VFS.DEV_97: 'https://download.lenovo.com/pccbbs/mobiles/n1mgf03w.exe', + VFS.DEV_90: { + 'driver': 'https://download.lenovo.com/pccbbs/mobiles/n1cgn08w.exe', + 'referral': 'https://support.lenovo.com/us/en/downloads/DS120491', + }, + VFS.DEV_97: { + 'driver': 'https://download.lenovo.com/pccbbs/mobiles/n1mgf03w.exe', + 'referral': 'https://download.lenovo.com/pccbbs/mobiles/n1mgf03w.exe' + } } DEFAULT_FW_NAMES = { @@ -88,13 +94,17 @@ class VFSInitializer(): self.open_device(init=True) def download_and_extract_fw(self, fwdir, fwuri=None): - fwuri = fwuri if fwuri else DEFAULT_URIS[self.dev_type] + fwuri = fwuri if fwuri else DEFAULT_URIS[self.dev_type]['driver'] fwarchive = os.path.join(fwdir, 'fwinstaller.exe') fwname = DEFAULT_FW_NAMES[self.dev_type] print('Downloading {} to extract {}'.format(fwuri, fwname)) - with urllib.request.urlopen(fwuri) as response: + req = urllib.request.Request(fwuri) + req.add_header('Referer', DEFAULT_URIS[self.dev_type].get('referral', '')) + req.add_header('User-Agent', 'Mozilla/5.0 (X11; U; Linux)') + + with urllib.request.urlopen(req) as response: with open(fwarchive, 'wb') as out_file: out_file.write(response.read())