# Buggy code
def get_device_info(self):
    device_info = dict()
    device_info["network_os"] = "junos"
    ele = new_ele("get-software-information")
    data = self.execute_rpc(to_xml(ele))
    reply = to_ele(to_bytes(data, errors="surrogate_or_strict"))
    sw_info = reply.find(".//software-information")

    device_info["network_os_version"] = self.get_text(sw_info, "junos-version")
    device_info["network_os_hostname"] = self.get_text(sw_info, "host-name")
    device_info["network_os_model"] = self.get_text(sw_info, "product-model")

    return device_info


# Traceback (TypeError)
ansible-playbook 2.4.3.0
config file = /home/am/test_cswt/ansible.cfg
configured module search path = ['/home/am/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/am/env2/lib/python3.6/site-packages/ansible
executable location = /home/am/env2/bin/ansible-playbook
python version = 3.6.3 (default, Feb  8 2018, 12:39:01) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
Using /home/am/test_cswt/ansible.cfg as config file
[DEPRECATION WARNING]: [defaults]hostfile option, The key is misleading as it can also be a list of hosts, a directory or a list of paths . This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
setting up inventory plugins
Parsed /home/am/test_cswt/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /home/am/env2/lib/python3.6/site-packages/ansible/plugins/callback/default.py

PLAYBOOK: dcag_juniper.yml *****************************************************************************************************************************************************************************************************************
1 plays in dcag_juniper.yml

PLAY [show version] ************************************************************************************************************************************************************************************************************************
META: ran handlers

TASK [show ver_juniper] ********************************************************************************************************************************************************************************************************************
task path: /home/am/test_cswt/dcag_juniper.yml:16
<x.x.x.x> using connection plugin netconf
<x.x.x.x> socket_path: /home/am/.ansible/pc/656d6bb5b3
Using module file /home/am/env2/lib/python3.6/site-packages/ansible/modules/network/junos/junos_command.py
<x.x.x.x> ESTABLISH LOCAL CONNECTION FOR USER: am
<x.x.x.x> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<x.x.x.x> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/am/.ansible/tmp/ansible-tmp-1518639080.5723124-44749168683326 `" &amp;&amp; echo ansible-tmp-1518639080.5723124-44749168683326="` echo /home/am/.ansible/tmp/ansible-tmp-1518639080.5723124-44749168683326 `" ) &amp;&amp; sleep 0'
<x.x.x.x> PUT /tmp/tmpk42qsj7u TO /home/am/.ansible/tmp/ansible-tmp-1518639080.5723124-44749168683326/junos_command.py
<x.x.x.x> EXEC /bin/sh -c 'chmod u+x /home/am/.ansible/tmp/ansible-tmp-1518639080.5723124-44749168683326/ /home/am/.ansible/tmp/ansible-tmp-1518639080.5723124-44749168683326/junos_command.py &amp;&amp; sleep 0'
<x.x.x.x> EXEC /bin/sh -c '/usr/bin/python /home/am/.ansible/tmp/ansible-tmp-1518639080.5723124-44749168683326/junos_command.py; rm -rf "/home/am/.ansible/tmp/ansible-tmp-1518639080.5723124-44749168683326/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_acLhAt/ansible_module_junos_command.py", line 446, in <module>
main()
File "/tmp/ansible_acLhAt/ansible_module_junos_command.py", line 394, in main
responses = rpc(module, items)
File "/tmp/ansible_acLhAt/ansible_module_junos_command.py", line 244, in rpc
reply = send_request(module, element, ignore_warning=False)
File "/tmp/ansible_acLhAt/ansible_modlib.zip/ansible/module_utils/netconf.py", line 42, in send_request
File "/tmp/ansible_acLhAt/ansible_modlib.zip/ansible/module_utils/connection.py", line 71, in exec_command
TypeError: int() can't convert non-string with explicit base
fatal: [x.x.x.x]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_acLhAt/ansible_module_junos_command.py\", line 446, in <module>\n    main()\n  File \"/tmp/ansible_acLhAt/ansible_module_junos_command.py\", line 394, in main\n    responses = rpc(module, items)\n  File \"/tmp/ansible_acLhAt/ansible_module_junos_command.py\", line 244, in rpc\n    reply = send_request(module, element, ignore_warning=False)\n  File \"/tmp/ansible_acLhAt/ansible_modlib.zip/ansible/module_utils/netconf.py\", line 42, in send_request\n  File \"/tmp/ansible_acLhAt/ansible_modlib.zip/ansible/module_utils/connection.py\", line 71, in exec_command\nTypeError: int() can't convert non-string with explicit base\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}
to retry, use: --limit @/home/am/test_cswt/dcag_juniper.retry

PLAY RECAP *********************************************************************************************************************************************************************************************************************************
x.x.x.x               : ok=0    changed=0    unreachable=0    failed=1

# Fixed code
def get_device_info(self):
    device_info = dict()
    device_info["network_os"] = "junos"
    ele = new_ele("get-software-information")
    data = self.execute_rpc(to_xml(ele))
    reply = to_ele(data)
    sw_info = reply.find(".//software-information")

    device_info["network_os_version"] = self.get_text(sw_info, "junos-version")
    device_info["network_os_hostname"] = self.get_text(sw_info, "host-name")
    device_info["network_os_model"] = self.get_text(sw_info, "product-model")

    return device_info