我不是程序员,但我想使用Python实现一些管理目的的自动化。
在“Hello world”之后,我尝试创建的第一个应用程序是交互式ssh客户端。
我阅读了一些文档和文章,认为这是使用paramiko模块的最简单方法,但不幸的是,我面临一个问题:
我的应用程序要求您输入一些必要的信息,如服务器ip、用户名、密码。在此之后,它将与定义的服务器建立连接,并在屏幕上为您提供cli。用于模拟输入while循环使用的命令的过程。
不幸的是,我的应用程序只有在您输入第一个命令时才能正常工作。尝试键入第二个命令时出现错误:Traceback (most recent call last):
File "C:\Python27\Tests\ssh_client.py", line 53, in
client.execute_command(command)
File "C:\Python27\Tests\ssh_client.py", line 26, in execute_command
stdin,stdout,stderr = self.connection.exec_command(command)
File "C:\Python27\lib\site-packages\paramiko\client.py", line 343, in exec_command
chan.exec_command(command)
AttributeError: 'NoneType' object has no attribute 'exec_command'
程序代码(Windows 7):import paramiko
SERVER