From 73669f59c824f6adef41956a46b7ea2fda52d313 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 17 Apr 2017 12:09:10 +0200 Subject: [PATCH] Use the `urllib.request.urlopen`'s `context` argument only if available. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `context` argument has been added to python 3.4.3 version. We must not use it for older version. Fix #31 --- kiwix-build.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kiwix-build.py b/kiwix-build.py index 1dfd656..49aeaa8 100755 --- a/kiwix-build.py +++ b/kiwix-build.py @@ -419,7 +419,8 @@ class BuildEnv: else: context = None batch_size = 1024 * 8 - with urllib.request.urlopen(file_url, context=context) as resource, open(file_path, 'wb') as file: + extra_args = {'context':context} if sys.version_info >= (3, 4, 3) else {} + with urllib.request.urlopen(file_url, **extra_args) as resource, open(file_path, 'wb') as file: while True: batch = resource.read(batch_size) if not batch: