From f7300c5c90a99d234a2c7a6d70f5b5baa9d35046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Fri, 21 Feb 2014 16:59:10 +0100 Subject: [PATCH] [generic] Fix on python 2.6 `ParseError` is not available, it raises `xml.parsers.expat.ExpatError`. The webpage needs to be encoded. --- youtube_dl/extractor/generic.py | 5 +++-- youtube_dl/utils.py | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/youtube_dl/extractor/generic.py b/youtube_dl/extractor/generic.py index 30160d59d4..9a2e54d149 100644 --- a/youtube_dl/extractor/generic.py +++ b/youtube_dl/extractor/generic.py @@ -13,6 +13,7 @@ compat_urllib_parse, compat_urllib_request, compat_urlparse, + compat_xml_parse_error, ExtractorError, HEADRequest, @@ -241,10 +242,10 @@ def _real_extract(self, url): # Is it an RSS feed? try: - doc = xml.etree.ElementTree.fromstring(webpage) + doc = xml.etree.ElementTree.fromstring(webpage.encode('utf-8')) if doc.tag == 'rss': return self._extract_rss(url, video_id, doc) - except xml.etree.ElementTree.ParseError: + except compat_xml_parse_error: pass # it's tempting to parse this further, but you would diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 057cd20d1d..471516b8f6 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -174,6 +174,11 @@ def compat_parse_qs(qs, keep_blank_values=False, strict_parsing=False, except NameError: compat_chr = chr +try: + from xml.etree.ElementTree import ParseError as compat_xml_parse_error +except ImportError: # Python 2.6 + from xml.parsers.expat import ExpatError as compat_xml_parse_error + def compat_ord(c): if type(c) is int: return c else: return ord(c)