sram客户端与paramiko(python)

时间:2011-05-12 23:18:15

标签: python ssh paramiko attributeerror

# sshpy v1 by s0urd
# simple ssh client 
# irc.gonullyourself.org 6667 #code

import paramiko
import os

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
privatekey = os.path.expanduser('/home/rabia/private')
mkey = paramiko.RSAKey.from_private_key_file(privatekey)
ssh.connect('78.46.172.47', port=22, username='s0urd', password=None, pkey=mkey)

while True:
      pick = raw_input("sshpy: ")
      stdin, stdout, stderr = ssh.exec_command(pick)
      print stdout.readlines()   
      ssh.close()

当我尝试运行超过1个命令时,我收到此错误:

AttributeError: 'NoneType' object has no attribute 'open_session'

1 个答案:

答案 0 :(得分:5)

看起来是因为在while循环结束时你执行了ssh.close()(从而关闭了会话)。