From 32eff4d07984b46fec87dc000c48e91879061cfc Mon Sep 17 00:00:00 2001 From: nicolargo Date: Tue, 27 Dec 2016 21:45:11 +0100 Subject: [PATCH] Correct encoding issue with AMP sustemd and Python 3.5 --- NEWS | 2 +- glances/amps/glances_systemd.py | 4 ++-- glances/compat.py | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 18e37227..9df521e5 100644 --- a/NEWS +++ b/NEWS @@ -15,7 +15,7 @@ Changes: Enhancements and new features: - * WebUI CPU consumption optimization (issue #836) + * WebUI CPU consumption optimization (issue #836) * Add ZeroMQ exporter (issue #939) * Add CouchDB exporter (issue #928) * Add hotspot Wifi informations (issue #937) diff --git a/glances/amps/glances_systemd.py b/glances/amps/glances_systemd.py index 5bee568d..2c1cde79 100644 --- a/glances/amps/glances_systemd.py +++ b/glances/amps/glances_systemd.py @@ -48,7 +48,7 @@ systemctl_cmd=/usr/bin/systemctl --plain from subprocess import check_output from glances.logger import logger -from glances.compat import iteritems +from glances.compat import iteritems, to_ascii from glances.amps.glances_amp import GlancesAmp @@ -76,7 +76,7 @@ class Amp(GlancesAmp): else: status = {} # For each line - for r in res.split('\n')[1:-8]: + for r in to_ascii(res).split('\n')[1:-8]: # Split per space .* l = r.split() if len(l) > 3: diff --git a/glances/compat.py b/glances/compat.py index 5a1f7b83..76fb7f1e 100644 --- a/glances/compat.py +++ b/glances/compat.py @@ -106,6 +106,8 @@ else: def to_ascii(s): """Convert the unicode 's' to a ASCII string Usefull to remove accent (diacritics)""" + if isinstance(s, binary_type): + return s return unicodedata.normalize('NFKD', s).encode('ASCII', 'ignore') def listitems(d):