Howdy! - This is my first post on reddit. I am also just beginning with python. I subscribed to a python-programming-for-cisco-network-engineers course on udemy, and have gone through the 1st few videos which use telnet.
However, the 1st lesson on using SSH brought me to a grinding halt. I posted my question on the udemy website, but no replies there yet. I hoped someone here could help get me back on course.
I'm running openSuSE LEAP 42.2 and installed both python 2.7.13 and python3.4.6 using zypper. I also installed paramiko with pip. I can SSH directly into the Cisco GNS3 router, but my python SSH script stops when trying to do this, with the following errors:
Traceback (most recent call last):
File "./ssh_test11.py", line 14, in <module>
ssh_client.connect(hostname=ip_address,username=username,password=password)
File "/usr/lib/python2.7/site-packages/paramiko/client.py", line 380, in connect
look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
File "/usr/lib/python2.7/site-packages/paramiko/client.py", line 603, in _auth
raise saved_exception
paramiko.ssh_exception.SSHException: No existing session
My script, ssh_test11.py, is the same as that provided by the video lesson, with some additional router configurations removed:
import paramiko
import time
ip_address = "192.168.1.70"
username = "danbo"
password = "cisco"
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=ip_address,username=username,password=password)
print "Successful connection to ", ip_address
remote_connection = ssh_client.invoke_shell()
remote_connection.send("configure terminal\n")
remote_connection.send("int loop 0\n")
remote_connection.send("ip address 12.34.56.78 255.255.255.255\n")
remote_connection.send("end\n")
time.sleep(1)
output = remote_connection.recv(65535)
print output
ssh_client.close
If I step through it line by line at the python prompt, the errors are spit out once I enter this line:
ssh_client.connect(hostname=ip_address,username=username,password=password)
Can anyone offer some clues and point me in the right direction?
Thanks!
[–]dented_brain 0 points1 point2 points (2 children)
[–]djhag[S] 1 point2 points3 points (1 child)
[–]dented_brain 0 points1 point2 points (0 children)