我有以下代码块:
class HwSwitch(object):
def __init__(self):
pass
def _create_channel(self):
try:
self.channel = self.ssh.invoke_shell()
except SSHException:
raise SSHException("Unable to invoke the SSH Command shell")
def _send_cmd_to_channel(self, cmd):
try:
time.sleep(1)
self.channel.send(cmd + '\r\n')
out = self.channel.recv(9999)
except SSHException:
raise SSHException("Execution of command '%s' failed" % cmd)
return str(out)
但我总是得到一个错误:AttributeError:'HwSwitch'对象没有属性'channel'。
问题似乎出在self.channel.send(cmd + '\r\n')
的某个地方,但我看不到哪里。有什么问题吗(可能是压痕?)。谢谢
您正在将'channel'作为实例变量访问,要么在
__init__
中创建它,要么在调用_send_cmd_to_channel
之前调用_create_channel
。在另请参考this
相关问题 更多 >
编程相关推荐