paramiko-expect with Python 2->3 'str' buffer interface issues?

Nick Ellson nickolas.ellson at gmail.com
Mon Mar 23 18:02:25 EDT 2015


Hello,

 

Newly trying out programming, Python for Network Engineers, and loving it.
So I found paramiko for SSH, and now paramiko-expect for ssh expect like
behavior.  I am using Python 3.4 and have been through a number of examples
of changing code to work in the 3.x environment. But is anyone using
paramiko-expect? 

 

It seems to have the usual 'str' type issue I have seen, and used
<var>.decode() for, but can't seem to make it happy with this module.  

 

Nick

 

Traceback (most recent call last):

  File "./ssh-expect.py", line 29, in <module>

    interact.expect(prompt)

  File "/usr/lib64/python3.4/site-packages/paramikoe.py", line 130, in
expect

    buffer = buffer.replace('\r', '')

TypeError: 'str' does not support the buffer interface

 

 

#!/usr/bin/env python

# PyNet Class Exercises by Nick Ellson

__author__ = "Nick Ellson"

import paramiko

from paramikoe import SSHClientInteraction

if __name__ == '__main__':

    ip = '10.10.10.10'

    username = 'user' 

    password = 'password'

    prompt = 'router#'

    remote_conn_pre = paramiko.SSHClient()

    remote_conn_pre.set_missing_host_key_policy(

         paramiko.AutoAddPolicy())

    remote_conn_pre.connect(ip, username=username, password=password,
allow_agent=False, look_for_keys=False)

    print ("SSH connection established to %s" % ip)

 

    interact = SSHClientInteraction(remote_conn_pre, timeout=10,
display=True)

    interact.expect(prompt)

    interact.send('terminal length 0')

    interact.expect(prompt)

    interact.send('show version')

    interact.expect(prompt)

    cmd_output = interact.current_output_clean

    print (cmd_output)

    remote_conn_pre.close()

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150323/fa8a30fb/attachment.html>


More information about the Python-list mailing list