1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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