From 6cdf258f61bef59db433ca69174ef2d7d829e932 Mon Sep 17 00:00:00 2001 From: Mike Marshall <45433824+mmarshallgh@users.noreply.github.com> Date: Mon, 10 Dec 2018 17:32:54 -0600 Subject: [PATCH] fix python 3.x str.decode exception (#877) * fix python 3.x str.decode exception * Moved try clause inside the if statement * Moved try clause inside the if statement --- elasticsearch/connection/base.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/elasticsearch/connection/base.py b/elasticsearch/connection/base.py index 3ea18fd5..d4fbe33d 100644 --- a/elasticsearch/connection/base.py +++ b/elasticsearch/connection/base.py @@ -76,7 +76,10 @@ class Connection(object): # body has already been serialized to utf-8, deserialize it for logging # TODO: find a better way to avoid (de)encoding the body back and forth if body: - body = body.decode('utf-8', 'ignore') + try: + body = body.decode('utf-8', 'ignore') + except AttributeError: + pass logger.info( '%s %s [status:%s request:%.3fs]', method, full_url, @@ -100,7 +103,10 @@ class Connection(object): # body has already been serialized to utf-8, deserialize it for logging # TODO: find a better way to avoid (de)encoding the body back and forth if body: - body = body.decode('utf-8', 'ignore') + try: + body = body.decode('utf-8', 'ignore') + except AttributeError: + pass logger.debug('> %s', body)