mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-25 20:22:36 +01:00
replace error handlers for stdout and co.
Python3.5 and lower throw an UnicodeEncodeError when trying to print not-encodable characters when not using 'utf-8' as encoding. Setting their error handlers to 'replace' should help.
This commit is contained in:
parent
f8168c693e
commit
0381ae5318
@ -27,7 +27,6 @@ from . import version, config, option, extractor, job, util, exception
|
||||
__version__ = version.__version__
|
||||
log = logging.getLogger("gallery-dl")
|
||||
|
||||
|
||||
def initialize_logging(loglevel, formatter):
|
||||
"""Setup basic logging functionality before configfiles have been loaded"""
|
||||
# convert levelnames to lowercase
|
||||
@ -42,6 +41,18 @@ def initialize_logging(loglevel, formatter):
|
||||
root.addHandler(handler)
|
||||
|
||||
|
||||
def replace_std_streams(errors="replace"):
|
||||
"""Replace standard streams and set their error handlers to 'errors'"""
|
||||
for name in ("stdout", "stdin", "stderr"):
|
||||
stream = getattr(sys, name)
|
||||
setattr(sys, name, stream.__class__(
|
||||
stream.buffer,
|
||||
errors=errors,
|
||||
newline=stream.newlines,
|
||||
line_buffering=stream.line_buffering,
|
||||
))
|
||||
|
||||
|
||||
def progress(urls, pformat):
|
||||
"""Wrapper around urls to output a simple progress indicator"""
|
||||
if pformat is True:
|
||||
@ -142,6 +153,9 @@ def parse_inputfile(file):
|
||||
|
||||
def main():
|
||||
try:
|
||||
if sys.stdout.encoding.lower() != "utf-8":
|
||||
replace_std_streams()
|
||||
|
||||
parser = option.build_parser()
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -21,6 +21,7 @@ TRAVIS_SKIP = {
|
||||
|
||||
# temporary issues, etc.
|
||||
BROKEN = {
|
||||
"imgyt", # "Name or service not known"
|
||||
"loveisover", # "Name or service not known"
|
||||
"luscious", # order changed, "Jump to Page" is gone
|
||||
"mangahere", # invalid SSL cert
|
||||
|
Loading…
Reference in New Issue
Block a user