Use to_text helper function to handle bytes and unicode

This commit is contained in:
Esteban Echeverry 2017-06-05 10:37:23 -05:00 committed by Toshio Kuratomi
parent 66040e0c9d
commit e8e73e0edd

View file

@ -33,7 +33,7 @@ import ssl
from ansible.module_utils.urls import generic_urlparse
from ansible.module_utils.six.moves.urllib.parse import urlparse
from ansible.module_utils.six.moves import http_client
from ansible.module_utils.six import PY2
from ansible.module_utils._text import to_text
# httplib/http.client connection using unix domain socket
HTTPConnection = http_client.HTTPConnection
@ -110,8 +110,7 @@ class LXDClient(object):
self.connection.request(method, url, body=body)
resp = self.connection.getresponse()
resp_data = resp.read()
if not PY2:
resp_data = resp_data.decode('utf-8')
resp_data = to_text(resp_data, errors='surrogate_or_strict')
resp_json = json.loads(resp_data)
self.logs.append({
'type': 'sent request',