Fix uptimerobot stacktrace on decode (#66244)

* Fix uptimerobot stacktrace on decode

`req.read()` always returns bytes whereas the json module expects
strings.

I don't know how this worked before.

* Use `module_utils._text.to_native` instead of decode
This commit is contained in:
koenw 2020-02-15 17:10:23 +01:00 committed by GitHub
parent 11483921f2
commit eaf879a7a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -59,6 +59,7 @@ import json
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import fetch_url
from ansible.module_utils._text import to_text
API_BASE = "https://api.uptimerobot.com/"
@ -79,7 +80,7 @@ def checkID(module, params):
data = urlencode(params)
full_uri = API_BASE + API_ACTIONS['status'] + data
req, info = fetch_url(module, full_uri)
result = req.read()
result = to_text(req.read())
jsonresult = json.loads(result)
req.close()
return jsonresult
@ -91,7 +92,7 @@ def startMonitor(module, params):
data = urlencode(params)
full_uri = API_BASE + API_ACTIONS['editMonitor'] + data
req, info = fetch_url(module, full_uri)
result = req.read()
result = to_text(req.read())
jsonresult = json.loads(result)
req.close()
return jsonresult['stat']
@ -103,7 +104,7 @@ def pauseMonitor(module, params):
data = urlencode(params)
full_uri = API_BASE + API_ACTIONS['editMonitor'] + data
req, info = fetch_url(module, full_uri)
result = req.read()
result = to_text(req.read())
jsonresult = json.loads(result)
req.close()
return jsonresult['stat']