Skip to content

Commit 63dcbc7

Browse files
committedJul 16, 2015
Fix getnikola/nikola-themes#49 -- https→http fallback
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
1 parent d9559f9 commit 63dcbc7

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed
 

‎CHANGES.txt

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Features
3333
Bugfixes
3434
--------
3535

36+
* Use ``http`` as fallback in plugin/theme installers if a SSL error occurs
37+
(Issue getnikola/nikola-themes#49)
3638
* Add missing ``xmlns:xhtml`` namespace to sitemaps (Issue #1890)
3739
* Fixed superfluous rebuild problems with Python 3. Note that this will cause
3840
rebuilds for most sites. (Issue #1887)

‎nikola/plugins/command/install_theme.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from __future__ import print_function
2828
import os
2929
import io
30-
import json
30+
import time
3131
import requests
3232

3333
import pygments
@@ -95,8 +95,13 @@ def _execute(self, options, args):
9595
if name is None and not listing:
9696
LOGGER.error("This command needs either a theme name or the -l option.")
9797
return False
98-
data = requests.get(url).text
99-
data = json.loads(data)
98+
try:
99+
data = requests.get(url).json()
100+
except requests.exceptions.SSLError:
101+
LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
102+
time.sleep(1)
103+
url = url.replace('http', 'https', 1)
104+
data = requests.get(url).json()
100105
if listing:
101106
print("Themes:")
102107
print("-------")
@@ -124,9 +129,18 @@ def _execute(self, options, args):
124129
def do_install(self, name, data):
125130
if name in data:
126131
utils.makedirs(self.output_dir)
127-
LOGGER.info("Downloading '{0}'".format(data[name]))
132+
url = data[name]
133+
LOGGER.info("Downloading '{0}'".format(url))
134+
try:
135+
zip_data = requests.get(url).content
136+
except requests.exceptions.SSLError:
137+
LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
138+
time.sleep(1)
139+
url = url.replace('http', 'https', 1)
140+
zip_data = requests.get(url).content
141+
128142
zip_file = io.BytesIO()
129-
zip_file.write(requests.get(data[name]).content)
143+
zip_file.write(zip_data)
130144
LOGGER.info("Extracting '{0}' into themes/".format(name))
131145
utils.extract_all(zip_file)
132146
dest_path = os.path.join(self.output_dir, name)

‎nikola/plugins/command/plugin.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import shutil
3131
import subprocess
3232
import sys
33+
import time
3334
import requests
3435

3536
import pygments
@@ -209,9 +210,18 @@ def do_install(self, url, name, show_install_notes=True):
209210
data = self.get_json(url)
210211
if name in data:
211212
utils.makedirs(self.output_dir)
212-
LOGGER.info('Downloading: ' + data[name])
213+
url = data[name]
214+
LOGGER.info("Downloading '{0}'".format(url))
215+
try:
216+
zip_data = requests.get(url).content
217+
except requests.exceptions.SSLError:
218+
LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
219+
time.sleep(1)
220+
url = url.replace('http', 'https', 1)
221+
zip_data = requests.get(url).content
222+
213223
zip_file = io.BytesIO()
214-
zip_file.write(requests.get(data[name]).content)
224+
zip_file.write(zip_data)
215225
LOGGER.info('Extracting: {0} into {1}/'.format(name, self.output_dir))
216226
utils.extract_all(zip_file, self.output_dir)
217227
dest_path = os.path.join(self.output_dir, name)
@@ -296,5 +306,11 @@ def do_uninstall(self, name):
296306

297307
def get_json(self, url):
298308
if self.json is None:
299-
self.json = requests.get(url).json()
309+
try:
310+
self.json = requests.get(url).json()
311+
except requests.exceptions.SSLError:
312+
LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
313+
time.sleep(1)
314+
url = url.replace('http', 'https', 1)
315+
self.json = requests.get(url).json()
300316
return self.json

0 commit comments

Comments
 (0)
Please sign in to comment.