From 00c455a7485b621603af1ba6cd4b055c88eabbf5 Mon Sep 17 00:00:00 2001 From: Peter Dahlberg Date: Mon, 9 May 2016 15:39:00 +0200 Subject: [PATCH] Quote URL before urlretrieve This avoids unicode errors with URLs conaining non-ascii characters --- pelican/tools/pelican_import.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pelican/tools/pelican_import.py b/pelican/tools/pelican_import.py index 204ab7b0..a36e89d5 100755 --- a/pelican/tools/pelican_import.py +++ b/pelican/tools/pelican_import.py @@ -13,7 +13,7 @@ import time from codecs import open from six.moves.urllib.error import URLError -from six.moves.urllib.parse import urlparse +from six.moves.urllib.parse import quote, urlparse from six.moves.urllib.request import urlretrieve # because logging.setLoggerClass has to be called before logging.getLogger @@ -667,7 +667,8 @@ def download_attachments(output_path, urls): os.makedirs(full_path) print('downloading {}'.format(filename)) try: - urlretrieve(url, os.path.join(full_path, filename)) + quote_url = quote(url, safe="%/:=&?~#+!$,;'@()*[]") + urlretrieve(quote_url, os.path.join(full_path, filename)) locations.append(os.path.join(localpath, filename)) except (URLError, IOError) as e: # Python 2.7 throws an IOError rather Than URLError