def sshConnection():
file = open('sessionLog.txt', 'w+')
while True:
try:
panIP = input("Panorama IP: ")
fwIP = input("Firewall IP: ")
username = input("Username: ")
password = getpass()
panosConn = ConnectHandler(device_type = "paloalto_panos", host = panIP, username = username, password = password, session_log = 'sessionLog.txt')
break
except (NetMikoAuthenticationException, NetMikoTimeoutException):
print("Authentication Failed")
pass
panosConn.send_command('ssh host '+username+'@'+fwIP+'', expect_string = r'Password')
panosConn.send_command(''+password+'', expect_string = r'>')
panosConn.find_prompt()
panosConn.send_command('set cli pager off')
Traceback (most recent call last):
File "C:\pyscripts\netmiko3\lib\site-packages\paramiko\channel.py", line 699, in recv
out = self.in_buffer.read(nbytes, self.timeout)
File "C:\pyscripts\netmiko3\lib\site-packages\paramiko\buffered_pipe.py", line 164, in read
raise PipeTimeout()
paramiko.buffered_pipe.PipeTimeoutDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\pyscripts\netmiko3\lib\site-packages\netmiko\base_connection.py", line 541, in _read_channel_expect
new_data = self.remote_conn.recv(MAX_BUFFER)
File "C:\pyscripts\netmiko3\lib\site-packages\paramiko\channel.py", line 701, in recv
raise socket.timeout()
socket.timeoutDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".\pacPeople.py", line 85, in
main()
File ".\pacPeople.py", line 81, in main
panosConn = sshConnection()
File ".\pacPeople.py", line 45, in sshConnection
panosConn.send_command('ssh host '+username+'@'+fwIP+'', expect_string = r'Password')
File "C:\pyscripts\netmiko3\lib\site-packages\netmiko\paloalto\paloalto_panos.py", line 160, in send_command
return super().send_command(args, *kwargs)
File "C:\pyscripts\netmiko3\lib\site-packages\netmiko\base_connection.py", line 1366, in send_command
new_data = self.read_until_pattern(pattern=re.escape(cmd))
File "C:\pyscripts\netmiko3\lib\site-packages\netmiko\base_connection.py", line 618, in read_until_pattern
return self._read_channel_expect(args, *kwargs)
File "C:\pyscripts\netmiko3\lib\site-packages\netmiko\base_connection.py", line 552, in _read_channel_expect
"Timed-out reading channel, data not available."
netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.
Using expect_string for ssh proxy through another device no longer working in ver 3.0.0 , was previously working in 2.4.2
@wfleisher What is the intermediate device that you are connecting through--i.e. what type of device is this?
Intermediate device is a Panorama appliance. End device is a palo alto firewall.
So basically Netmiko is saying that this command:
'ssh host '+username+'@'+fwIP+''
Was supposed to be echoed to the screen and it never happened.
Can you turn on Netmiko logging and see if we can get more details on what happened?
https://github.com/ktbyers/netmiko/blob/develop/COMMON_ISSUES.md#enable-netmiko-logging-of-all-reads-and-writes-of-the-communications-channel
You can just obfuscate anything in the log file that is confidential.
test.log
Here is the log file.
Is that your obfuscation there?
[Kusername@Panorama-Hostname(secondary-active)> ssh host username@10 .15.12.**
Did you add the extra space after the 10?
Also, is the IP fully correct here. The lines I am talking about are here (I assume that ** is your obfuscation as well)?
DEBUG:netmiko:_read_channel_expect read_data: ssh
[Kusername@Panorama-Hostname(secondary-active)> ssh host
[Kusername@Panorama-Hostname(secondary-active)> ssh host username@10 .15.12.**
No only replaced the last octet. The space is present in the log when I run the script in 2.4.2 as well
Okay, it looks like there are ANSI escape codes in the output that are messing things up:
In [5]: repr(line)
Out[5]: "'\\x1b[Kusername@Panorama-Hostname(secondary-active)> ssh host username@10 \\x08.15.12.**'"
We'll have to figure out what to do with that.
Netmiko 2.4.2 is different than Netmiko 3.0.0 here (Netmiko 3.0.0 is trying to verify the command echo whereas Netmiko 2.4.2 didn't)...so that part is expected.
Verifying the command echo fixes a lot of other Netmiko problems.
test.log
Submitted a pull request with a fix for this. Attached is a log run with the added code.
Pull request