# Buggy code
def send_request(self, commands, output="text"):
    commands = to_list(commands)

    if self._enable:
        commands.insert(0, "enable")

    body = self._request_builder(commands, output)
    data = self._module.jsonify(body)

    headers = {"Content-Type": "application/json-rpc"}
    timeout = self._module.params["timeout"]

    response, headers = fetch_url(
        self._module,
        self._url,
        data=data,
        headers=headers,
        method="POST",
        timeout=timeout,
    )

    if headers["status"] != 200:
        self._module.fail_json(**headers)

    try:
        data = response.read()
        response = self._module.from_json(
            to_text(data, errors="surrogate_then_replace")
        )
    except ValueError:
        self._module.fail_json(msg="unable to load response from device", data=data)

    if self._enable and "result" in response:
        response["result"].pop(0)

    return response


# Traceback (KeyError)
<192.168.80.101> connection transport is eapi
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/basic.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/eos.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/netcfg.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/_text.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/parsing/convert_bool.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/parsing/__init__.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/pycompat24.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/six/__init__.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/connection.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/network_common.py
Using module_utils file /usr/lib/python2.7/dist-packages/ansible/module_utils/urls.py
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/network/eos/eos_config.py
<192.168.80.101> ESTABLISH LOCAL CONNECTION FOR USER: krzysiek
<192.168.80.101> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<192.168.80.101> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/krzysiek/.ansible/tmp/ansible-tmp-1506192409.08-244809892338109 `" &amp;&amp; echo ansible-tmp-1506192409.08-244809892338109="` echo /home/krzysiek/.ansible/tmp/ansible-tmp-1506192409.08-244809892338109 `" ) &amp;&amp; sleep 0'
<192.168.80.101> PUT /tmp/tmpeT1eTQ TO /home/krzysiek/.ansible/tmp/ansible-tmp-1506192409.08-244809892338109/eos_config.py
<192.168.80.101> EXEC /bin/sh -c 'chmod u+x /home/krzysiek/.ansible/tmp/ansible-tmp-1506192409.08-244809892338109/ /home/krzysiek/.ansible/tmp/ansible-tmp-1506192409.08-244809892338109/eos_config.py &amp;&amp; sleep 0'
<192.168.80.101> EXEC /bin/sh -c '/usr/bin/python /home/krzysiek/.ansible/tmp/ansible-tmp-1506192409.08-244809892338109/eos_config.py; rm -rf "/home/krzysiek/.ansible/tmp/ansible-tmp-1506192409.08-244809892338109/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_i7Ofp_/ansible_module_eos_config.py", line 469, in <module>
main()
File "/tmp/ansible_i7Ofp_/ansible_module_eos_config.py", line 362, in main
contents = get_config(module)
File "/tmp/ansible_i7Ofp_/ansible_modlib.zip/ansible/module_utils/eos.py", line 462, in get_config
File "/tmp/ansible_i7Ofp_/ansible_modlib.zip/ansible/module_utils/eos.py", line 377, in get_config
KeyError: 'result'

fatal: [192.168.80.101]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_i7Ofp_/ansible_module_eos_config.py\", line 469, in <module>\n    main()\n  File \"/tmp/ansible_i7Ofp_/ansible_module_eos_config.py\", line 362, in main\n    contents = get_config(module)\n  File \"/tmp/ansible_i7Ofp_/ansible_modlib.zip/ansible/module_utils/eos.py\", line 462, in get_config\n  File \"/tmp/ansible_i7Ofp_/ansible_modlib.zip/ansible/module_utils/eos.py\", line 377, in get_config\nKeyError: 'result'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def send_request(self, commands, output="text"):
    commands = to_list(commands)

    if self._enable:
        commands.insert(0, self._enable)

    body = self._request_builder(commands, output)
    data = self._module.jsonify(body)

    headers = {"Content-Type": "application/json-rpc"}
    timeout = self._module.params["timeout"]

    response, headers = fetch_url(
        self._module,
        self._url,
        data=data,
        headers=headers,
        method="POST",
        timeout=timeout,
    )

    if headers["status"] != 200:
        self._module.fail_json(**headers)

    try:
        data = response.read()
        response = self._module.from_json(
            to_text(data, errors="surrogate_then_replace")
        )
    except ValueError:
        self._module.fail_json(msg="unable to load response from device", data=data)

    if self._enable and "result" in response:
        response["result"].pop(0)

    return response