Trigger with Django FrontEnd

38 views
Skip to first unread message

Jay K

unread,
Nov 18, 2014, 2:22:03 PM11/18/14
to trigge...@googlegroups.com
Hi Folks,

Just wanted to get your inputs on the error I am facing. We have a web application that lets users run commands across multiple vendor network platforms. While this works great with platforms that have openAPI's, we decided to use trigger/commando for the legacy Cisco stuff. Trigger is really cool, here is a simple function we have

def cisco(deviceList, showCommand):
    result = {}
    devices = deviceList.splitlines()
    c = Commando(devices=devices, commands=showCommand, creds=(username,password))
    c.run()
    for device in c.results.keys():
        for command_result in c.results.values():
            result[device] = command_result.values()
    return result

while I try to execute this code, I get the following exception:

[Tue Nov 18 16:50:22.004975 2014] [:error] [pid 16361]   File "/opt/rh/python27/root/usr/lib64/python2.7/site-packages/twisted/conch/ssh/transport.py", line 358, in sendPacket
[Tue Nov 18 16:50:22.004986 2014] [:error] [pid 16361]     payload + randbytes.secureRandom(lenPad))
[Tue Nov 18 16:50:22.004997 2014] [:error] [pid 16361] exceptions.UnicodeDecodeError: 'ascii' codec can't decode byte 0xa7 in position 1: ordinal not in range(128)

I have tried to change to other encoding (utf-8) types but get similar error for other coding types. The code works perfectly fine through the Django shell. I have researched through stack overflow but seem to have hit a wall. So just wanted to see if you have any pointers on how I could proceed.

Thanks.

Regards,
Jay

Jathan McCollum

unread,
Nov 18, 2014, 4:06:15 PM11/18/14
to trigge...@googlegroups.com
The underlying Twisted library that is used by Trigger for SSH connections doesn't like Unicode. So, before you hand over to Trigger to execute things, you need to make sure you're explicitly casting Unicode strings to regular strings. For Python 2.x this would be as simple as using the str() constructor.

If your payload is something other than a string, such as a dictionary, you need to make sure that the dictionary keys aren't Unicode strings.

Give this a try and let me know if you're still having issues.

--
You received this message because you are subscribed to the Google Groups "Trigger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trigger-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jathan.
--
Reply all
Reply to author
Forward
0 new messages