From 6b55c5d498ecdda2ebd6cc15109179fc09c99b08 Mon Sep 17 00:00:00 2001 From: weiyang Date: Sun, 28 May 2017 00:10:42 +0800 Subject: [PATCH] [update_plugins] Replace 'requests' with 'urlopen' Signed-off-by: weiyang --- update_plugins.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/update_plugins.py b/update_plugins.py index 793e406f..4f0bfde6 100755 --- a/update_plugins.py +++ b/update_plugins.py @@ -10,7 +10,12 @@ except ImportError: import zipfile import shutil import tempfile -import requests +try: + # For Python 3.0 and later + from urllib.request import urlopen +except ImportError: + # Fall back to Python 2's urllib2 + from urllib2 import urlopen from os import path @@ -64,8 +69,8 @@ def download_extract_replace(plugin_name, zip_path, temp_dir, source_dir): temp_zip_path = path.join(temp_dir, plugin_name) # Download and extract file in temp dir - req = requests.get(zip_path) - open(temp_zip_path, 'wb').write(req.content) + resp = urlopen(zip_path) + open(temp_zip_path, 'wb').write(resp.read()) zip_f = zipfile.ZipFile(temp_zip_path) zip_f.extractall(temp_dir)