我正在做一个网络配置项目。我想在 cisco nexus 交换机上启用密码加密以进行密码加密。我需要在命令执行后处理提示,这是我的 python 代码:
def audit_password_encryption():
pass_encryption = False
output = net_connect.send_command('show encryption service stat')
if(str.__contains__(output,"not being used")):
a = input("Şifreler clear-text formatında tutuluyor. AES şifrelemeyi konfigüre etmek ister misiniz? EVET[1] HAYIR[2]")
if a==str(1):
do_password_encryption()
def do_password_encryption():
passw = input("16-64 karakter sayisinda bir master key girin : ")
output=net_connect.send_command(
command_string='key config-key ascii',
expect_string=r"New Master Key:",
strip_prompt=False,
strip_command=False
)
output += net_connect.send_command(
command_string=passw+"\n",
expect_string=r"Retype Master Key:",
strip_prompt=False,
strip_command=False
)
output += net_connect.send_command(
command_string=passw+"\n",
expect_string=r"#",
strip_prompt=False,
strip_command=False
)
config_commands = ['feature password encryption aes']
net_connect.send_config_set(config_commands)
执行后出现如下错误:
File "/usr/local/lib/python3.8/dist-packages/paramiko/channel.py", line 699, in recv
out = self.in_buffer.read(nbytes, self.timeout)
File "/usr/local/lib/python3.8/dist-packages/paramiko/buffered_pipe.py", line 164, in read
raise PipeTimeout()
paramiko.buffered_pipe.PipeTimeout
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 569, in
_read_channel_expect
new_data = self.remote_conn.recv(MAX_BUFFER)
File "/usr/local/lib/python3.8/dist-packages/paramiko/channel.py", line 701, in recv
raise socket.timeout()
socket.timeout
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "sshpy.py", line 244, in <module>
audit_password_encryption()
File "sshpy.py", line 239, in audit_password_encryption
do_password_encryption()
File "sshpy.py", line 215, in do_password_encryption
output += net_connect.send_command(
File "/usr/local/lib/python3.8/dist-packages/netmiko/utilities.py", line 430, in
wrapper_decorator
return func(self, *args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 1490, in
send_command
new_data = self.read_until_pattern(pattern=re.escape(cmd))
File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 651, in
read_until_pattern
return self._read_channel_expect(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/netmiko/base_connection.py", line 579, in
_read_channel_expect
raise NetmikoTimeoutException(
netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.
为什么我会收到此错误?或者你有什么想法在命令执行后处理提示?谢谢