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:
parent
11483921f2
commit
eaf879a7a7
1 changed files with 4 additions and 3 deletions
|
@ -59,6 +59,7 @@ import json
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.urls import fetch_url
|
||||||
|
from ansible.module_utils._text import to_text
|
||||||
|
|
||||||
|
|
||||||
API_BASE = "https://api.uptimerobot.com/"
|
API_BASE = "https://api.uptimerobot.com/"
|
||||||
|
@ -79,7 +80,7 @@ def checkID(module, params):
|
||||||
data = urlencode(params)
|
data = urlencode(params)
|
||||||
full_uri = API_BASE + API_ACTIONS['status'] + data
|
full_uri = API_BASE + API_ACTIONS['status'] + data
|
||||||
req, info = fetch_url(module, full_uri)
|
req, info = fetch_url(module, full_uri)
|
||||||
result = req.read()
|
result = to_text(req.read())
|
||||||
jsonresult = json.loads(result)
|
jsonresult = json.loads(result)
|
||||||
req.close()
|
req.close()
|
||||||
return jsonresult
|
return jsonresult
|
||||||
|
@ -91,7 +92,7 @@ def startMonitor(module, params):
|
||||||
data = urlencode(params)
|
data = urlencode(params)
|
||||||
full_uri = API_BASE + API_ACTIONS['editMonitor'] + data
|
full_uri = API_BASE + API_ACTIONS['editMonitor'] + data
|
||||||
req, info = fetch_url(module, full_uri)
|
req, info = fetch_url(module, full_uri)
|
||||||
result = req.read()
|
result = to_text(req.read())
|
||||||
jsonresult = json.loads(result)
|
jsonresult = json.loads(result)
|
||||||
req.close()
|
req.close()
|
||||||
return jsonresult['stat']
|
return jsonresult['stat']
|
||||||
|
@ -103,7 +104,7 @@ def pauseMonitor(module, params):
|
||||||
data = urlencode(params)
|
data = urlencode(params)
|
||||||
full_uri = API_BASE + API_ACTIONS['editMonitor'] + data
|
full_uri = API_BASE + API_ACTIONS['editMonitor'] + data
|
||||||
req, info = fetch_url(module, full_uri)
|
req, info = fetch_url(module, full_uri)
|
||||||
result = req.read()
|
result = to_text(req.read())
|
||||||
jsonresult = json.loads(result)
|
jsonresult = json.loads(result)
|
||||||
req.close()
|
req.close()
|
||||||
return jsonresult['stat']
|
return jsonresult['stat']
|
||||||
|
|
Loading…
Reference in a new issue