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
This commit is contained in:
Mike Marshall
2018-12-10 16:32:54 -07:00
committed by Nick Lang
parent b8c241d5ec
commit 6cdf258f61
+8 -2
View File
@@ -76,7 +76,10 @@ class Connection(object):
# body has already been serialized to utf-8, deserialize it for logging # 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 # TODO: find a better way to avoid (de)encoding the body back and forth
if body: if body:
body = body.decode('utf-8', 'ignore') try:
body = body.decode('utf-8', 'ignore')
except AttributeError:
pass
logger.info( logger.info(
'%s %s [status:%s request:%.3fs]', method, full_url, '%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 # 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 # TODO: find a better way to avoid (de)encoding the body back and forth
if body: if body:
body = body.decode('utf-8', 'ignore') try:
body = body.decode('utf-8', 'ignore')
except AttributeError:
pass
logger.debug('> %s', body) logger.debug('> %s', body)