使用ssh和paramiko在远程系统上执行命令时。执行时会出现错误
def execute(self,command):
to_exec = self.transport.open_session()
to_exec.exec_command(command)
stdout.write("\r%s" % "Executed")
stdout.flush()
get_connection.execute('sh /etc/botclient/avail_pack.sh')
File "/home/xxx/project/server/ssh_module.py", line 43, in execute
to_exec = self.transport.open_session()
AttributeError: ssh_connection instance has no attribute 'transport'
答案 0 :(得分:1)
您还没有Transport
流对象。也许尝试用这样的self.transport = self.get_transport()
创建一个:
def execute(self,command):
self.transport = self.get_transport()
to_exec = self.transport.open_session()
to_exec.exec_command(command)
stdout.write("\r%s" % "Executed")
stdout.flush()
get_connection.execute('sh /etc/botclient/avail_pack.sh')
如果这不起作用,你将不得不向我们提供更多信息。