mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-02 17:22:31 +01:00
Properly convert errors to strings
This commit is contained in:
parent
fdae235858
commit
7f8b271465
@ -48,6 +48,7 @@
|
||||
determine_ext,
|
||||
DownloadError,
|
||||
encodeFilename,
|
||||
error_to_str,
|
||||
ExtractorError,
|
||||
format_bytes,
|
||||
formatSeconds,
|
||||
@ -681,7 +682,7 @@ def extract_info(self, url, download=True, ie_key=None, extra_info={},
|
||||
raise
|
||||
except Exception as e:
|
||||
if self.params.get('ignoreerrors', False):
|
||||
self.report_error(compat_str(e), tb=compat_str(traceback.format_exc()))
|
||||
self.report_error(error_to_str(e), tb=compat_str(traceback.format_exc()))
|
||||
break
|
||||
else:
|
||||
raise
|
||||
@ -1459,7 +1460,7 @@ def process_info(self, info_dict):
|
||||
if dn and not os.path.exists(dn):
|
||||
os.makedirs(dn)
|
||||
except (OSError, IOError) as err:
|
||||
self.report_error('unable to create directory ' + compat_str(err))
|
||||
self.report_error('unable to create directory ' + error_to_str(err))
|
||||
return
|
||||
|
||||
if self.params.get('writedescription', False):
|
||||
@ -2039,4 +2040,4 @@ def _write_thumbnails(self, info_dict, filename):
|
||||
(info_dict['extractor'], info_dict['id'], thumb_display_id, thumb_filename))
|
||||
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
|
||||
self.report_warning('Unable to download thumbnail "%s": %s' %
|
||||
(t['url'], compat_str(err)))
|
||||
(t['url'], error_to_str(err)))
|
||||
|
@ -5,9 +5,9 @@
|
||||
import sys
|
||||
import time
|
||||
|
||||
from ..compat import compat_str
|
||||
from ..utils import (
|
||||
encodeFilename,
|
||||
error_to_str,
|
||||
decodeArgument,
|
||||
format_bytes,
|
||||
timeconvert,
|
||||
@ -186,7 +186,7 @@ def try_rename(self, old_filename, new_filename):
|
||||
return
|
||||
os.rename(encodeFilename(old_filename), encodeFilename(new_filename))
|
||||
except (IOError, OSError) as err:
|
||||
self.report_error('unable to rename file: %s' % compat_str(err))
|
||||
self.report_error('unable to rename file: %s' % error_to_str(err))
|
||||
|
||||
def try_utime(self, filename, last_modified_hdr):
|
||||
"""Try to set the last-modified time of the given file."""
|
||||
|
@ -30,11 +30,11 @@
|
||||
clean_html,
|
||||
compiled_regex_type,
|
||||
determine_ext,
|
||||
error_to_str,
|
||||
ExtractorError,
|
||||
fix_xml_ampersands,
|
||||
float_or_none,
|
||||
int_or_none,
|
||||
preferredencoding,
|
||||
RegexNotFoundError,
|
||||
sanitize_filename,
|
||||
sanitized_Request,
|
||||
@ -333,12 +333,8 @@ def _request_webpage(self, url_or_request, video_id, note=None, errnote=None, fa
|
||||
return False
|
||||
if errnote is None:
|
||||
errnote = 'Unable to download webpage'
|
||||
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)
|
||||
|
||||
errmsg = '%s: %s' % (errnote, error_to_str(err))
|
||||
if fatal:
|
||||
raise ExtractorError(errmsg, sys.exc_info()[2], cause=err)
|
||||
else:
|
||||
@ -628,7 +624,7 @@ def _get_login_info(self):
|
||||
else:
|
||||
raise netrc.NetrcParseError('No authenticators for %s' % self._NETRC_MACHINE)
|
||||
except (IOError, netrc.NetrcParseError) as err:
|
||||
self._downloader.report_warning('parsing .netrc: %s' % compat_str(err))
|
||||
self._downloader.report_warning('parsing .netrc: %s' % error_to_str(err))
|
||||
|
||||
return (username, password)
|
||||
|
||||
|
@ -7,10 +7,10 @@
|
||||
|
||||
from .common import InfoExtractor
|
||||
|
||||
from ..compat import compat_str
|
||||
from ..utils import (
|
||||
ExtractorError,
|
||||
determine_ext,
|
||||
error_to_str,
|
||||
ExtractorError,
|
||||
int_or_none,
|
||||
parse_iso8601,
|
||||
sanitized_Request,
|
||||
@ -278,7 +278,7 @@ def _get_subtitles(self, video_id, webpage):
|
||||
'https://api.dailymotion.com/video/%s/subtitles?fields=id,language,url' % video_id,
|
||||
video_id, note=False)
|
||||
except ExtractorError as err:
|
||||
self._downloader.report_warning('unable to download video subtitles: %s' % compat_str(err))
|
||||
self._downloader.report_warning('unable to download video subtitles: %s' % error_to_str(err))
|
||||
return {}
|
||||
info = json.loads(sub_list)
|
||||
if (info['total'] > 0):
|
||||
|
@ -7,11 +7,11 @@
|
||||
from .common import InfoExtractor
|
||||
from ..compat import (
|
||||
compat_http_client,
|
||||
compat_str,
|
||||
compat_urllib_error,
|
||||
compat_urllib_parse_unquote,
|
||||
)
|
||||
from ..utils import (
|
||||
error_to_str,
|
||||
ExtractorError,
|
||||
limit_length,
|
||||
sanitized_Request,
|
||||
@ -116,7 +116,7 @@ def _login(self):
|
||||
if re.search(r'id="checkpointSubmitButton"', check_response) is not None:
|
||||
self._downloader.report_warning('Unable to confirm login, you have to login in your brower and authorize the login.')
|
||||
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
|
||||
self._downloader.report_warning('unable to log in: %s' % compat_str(err))
|
||||
self._downloader.report_warning('unable to log in: %s' % error_to_str(err))
|
||||
return
|
||||
|
||||
def _real_initialize(self):
|
||||
|
@ -26,6 +26,7 @@
|
||||
from ..utils import (
|
||||
clean_html,
|
||||
encode_dict,
|
||||
error_to_str,
|
||||
ExtractorError,
|
||||
float_or_none,
|
||||
get_element_by_attribute,
|
||||
@ -903,7 +904,7 @@ def _get_subtitles(self, video_id, webpage):
|
||||
'https://video.google.com/timedtext?hl=en&type=list&v=%s' % video_id,
|
||||
video_id, note=False)
|
||||
except ExtractorError as err:
|
||||
self._downloader.report_warning('unable to download video subtitles: %s' % compat_str(err))
|
||||
self._downloader.report_warning('unable to download video subtitles: %s' % error_to_str(err))
|
||||
return {}
|
||||
|
||||
sub_lang_list = {}
|
||||
|
Loading…
Reference in New Issue
Block a user