I have a Juniper router and I am trying to automate some of my tasks using Python 3.7.1. My code is running some commands perfectly but some commands are giving errors. Following is my code
import paramiko
def sshConnection(ip,command):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, port=22, username='username', password='password')
stdin, stdout, stderr = ssh.exec_command(command)
output = stdout.readlines()
return output
ip = '10.1.1.1'
command = 'show interfaces descriptions | match 1000 | no-more'
output = sshConnection(ip,command)
print('\n'.join(output))
Following is the error I am facing
Traceback (most recent call last):
File "C:\Users\Mu\Documents\Python Code\write_file - Stackoverflow.py", line 16, in <module>
output = sshConnection(ip,command)
File "C:\Users\Mu\Documents\Python Code\write_file - Stackoverflow.py", line 10, in sshConnection
output = stdout.readlines()
File "C:\Users\Mu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\paramiko\file.py", line 349, in readlines
line = self.readline()
File "C:\Users\Mu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\paramiko\file.py", line 334, in readline
return line if self._flags & self.FLAG_BINARY else u(line)
File "C:\Users\Mu\AppData\Local\Programs\Python\Python37-32\lib\site-packages\paramiko\py3compat.py", line 156, in u
return s.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 37: invalid start byte
Other router commands such as 'show version' is working fine and showing correct output. It seems the output contains some characters that are not accepted by UTF-8 encoding. I am unable to find the solution for this problem. Please help me resolve this. Thank you.