From 0484e87cd47b3d36482e805e3b29d003dd84fb1f Mon Sep 17 00:00:00 2001 From: Nathaniel Case Date: Tue, 17 Sep 2019 14:29:19 -0400 Subject: [PATCH] [stable-2.9] Fix "JSON object must be str, bytes or bytearray, not list" (#62418) * [stable-2.9] Fix "JSON object must be str, bytes or bytearray, not list" (#62350) (cherry picked from commit 84d9b3e) Co-authored-by: Nathaniel Case * Add changelog --- changelogs/fragments/62350-eapi-json-fix.yaml | 2 ++ lib/ansible/plugins/httpapi/eos.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/62350-eapi-json-fix.yaml diff --git a/changelogs/fragments/62350-eapi-json-fix.yaml b/changelogs/fragments/62350-eapi-json-fix.yaml new file mode 100644 index 00000000000..4b5989e6961 --- /dev/null +++ b/changelogs/fragments/62350-eapi-json-fix.yaml @@ -0,0 +1,2 @@ +bugfixes: +- Fixed intermittent "JSON object must be str, bytes or bytearray, not list" error with EOS over httpapi diff --git a/lib/ansible/plugins/httpapi/eos.py b/lib/ansible/plugins/httpapi/eos.py index 2221eb8c858..325c31ede61 100644 --- a/lib/ansible/plugins/httpapi/eos.py +++ b/lib/ansible/plugins/httpapi/eos.py @@ -68,7 +68,8 @@ class HttpApi(HttpApiBase): def send_request(self, data, **message_kwargs): data = to_list(data) - if self._become: + become = self._become + if become: self.connection.queue_message('vvvv', 'firing event: on_become') data.insert(0, {"cmd": "enable", "input": self._become_pass}) @@ -87,7 +88,7 @@ class HttpApi(HttpApiBase): results = handle_response(response_data) - if self._become: + if become: results = results[1:] if len(results) == 1: results = results[0] @@ -101,7 +102,7 @@ class HttpApi(HttpApiBase): device_info = {} device_info['network_os'] = 'eos' - reply = self.send_request('show version | json') + reply = self.send_request('show version', output='json') data = json.loads(reply) device_info['network_os_version'] = data['version']