Use to_text helper function to handle bytes and unicode

pull/21111/merge
Esteban Echeverry 7 years ago committed by Toshio Kuratomi
parent 66040e0c9d
commit e8e73e0edd

@ -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',

Loading…
Cancel
Save