aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2015-12-20 02:43:50 +0600
committerSergey M․ <dstftw@gmail.com>2015-12-20 02:43:50 +0600
commitdd85e4d70787dd0c106fb05bdb0a38f51037fd39 (patch)
tree3af3d5ad4f9b8c441cc85f259d330150a583a184
parentfa64a8431166ad7ca7bd2881306ee379b6e2abfd (diff)
downloadyoutube-dl-dd85e4d70787dd0c106fb05bdb0a38f51037fd39.tar.xz
[extractor/common] Properly decode error string on python 2 (Closes #1354, closes #3957, closes #4037, closes #6449)
-rw-r--r--youtube_dl/extractor/common.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py
index 6ab2d68d6..3ab72ff76 100644
--- a/youtube_dl/extractor/common.py
+++ b/youtube_dl/extractor/common.py
@@ -34,6 +34,7 @@ from ..utils import (
fix_xml_ampersands,
float_or_none,
int_or_none,
+ preferredencoding,
RegexNotFoundError,
sanitize_filename,
sanitized_Request,
@@ -332,7 +333,12 @@ class InfoExtractor(object):
return False
if errnote is None:
errnote = 'Unable to download webpage'
- errmsg = '%s: %s' % (errnote, compat_str(err))
+ err_str = str(err)
+ # On python 2 error byte string must be decoded with proper
+ # encoding rather than ascii
+ if sys.version_info[0] < 3:
+ err_str = err_str.decode(preferredencoding())
+ errmsg = '%s: %s' % (errnote, err_str)
if fatal:
raise ExtractorError(errmsg, sys.exc_info()[2], cause=err)
else: