diff --git a/lib/ansible/plugins/httpapi/eos.py b/lib/ansible/plugins/httpapi/eos.py index b079351d8f0..dc5d2059b6d 100644 --- a/lib/ansible/plugins/httpapi/eos.py +++ b/lib/ansible/plugins/httpapi/eos.py @@ -34,7 +34,11 @@ class HttpApi: headers = {'Content-Type': 'application/json-rpc'} response = self.connection.send('/command-api', request, headers=headers, method='POST') - response = json.loads(to_text(response.read())) + response_text = to_text(response.read()) + try: + response = json.loads(response_text) + except ValueError: + raise ConnectionError('Response was not valid JSON, got {0}'.format(response_text)) results = handle_response(response) if self._become: diff --git a/lib/ansible/plugins/httpapi/nxos.py b/lib/ansible/plugins/httpapi/nxos.py index d6cfc4fe1d3..13385da58fc 100644 --- a/lib/ansible/plugins/httpapi/nxos.py +++ b/lib/ansible/plugins/httpapi/nxos.py @@ -29,7 +29,12 @@ class HttpApi: headers = {'Content-Type': 'application/json'} response = self.connection.send('/ins', request, headers=headers, method='POST') - response = json.loads(to_text(response.read())) + response_text = to_text(response.read()) + try: + response = json.loads(response_text) + except ValueError: + raise ConnectionError('Response was not valid JSON, got {0}'.format(response_text)) + results = handle_response(response) if self._become: