From 94ffd00328af29304110df55ceffe2863b4afaf8 Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 11 Jul 2018 13:21:53 +0200 Subject: [PATCH] fixes initialization bug if sys.stdout.encoding is None (closes gh-2177). --- fail2ban/helpers.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fail2ban/helpers.py b/fail2ban/helpers.py index 5681c31b..49a5ca47 100644 --- a/fail2ban/helpers.py +++ b/fail2ban/helpers.py @@ -32,11 +32,10 @@ from threading import Lock from .server.mytime import MyTime - PREFER_ENC = locale.getpreferredencoding() # correct preferred encoding if lang not set in environment: if PREFER_ENC.startswith('ANSI_'): # pragma: no cover - if sys.stdout and not sys.stdout.encoding.startswith('ANSI_'): + if sys.stdout and sys.stdout.encoding is not None and not sys.stdout.encoding.startswith('ANSI_'): PREFER_ENC = sys.stdout.encoding elif all((os.getenv(v) in (None, "") for v in ('LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LANG'))): PREFER_ENC = 'UTF-8';