Chinaunix

标题: 错在哪? 新手指教 [打印本页]

作者: fllintel    时间: 2011-11-14 19:45
标题: 错在哪? 新手指教
  1. import paramiko

  2. def Myssh(ip,user,pw,pt):
  3.         myssh= paramiko.SSHClient()
  4.         myssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  5.         myssh.connect(ip,username=user,password=pw,port=pt)
  6.         i,o,e=myssh.exec_command("ls")
  7.         print o.read()
  8.         myssh.close()

  9. file=open("test.txt","r")
  10. user="test"
  11. for line in file.readlines():
  12.         x=line.split()
  13.         ip1=x[0]
  14.         pw1=x[1]
  15.         pt1=x[2]
  16.         print ip1,pw1,pt1
  17.         Myssh(ip1,user,pw1,pt1)
复制代码
执行后出现 :
  1. 127.0.0.1 abc123 22
  2. Traceback (most recent call last):
  3.   File "myssh.py", line 22, in ?
  4.     Myssh(ip1,user,pw1,pt1)
  5.   File "myssh.py", line 9, in Myssh
  6.     myssh.connect(ip,username=user,password=pw,port=pt)
  7.   File "build/bdist.linux-i686/egg/paramiko/client.py", line 310, in connect
  8. TypeError: int argument required
复制代码
我是想 去读一个文件, 里面有ip,密码 和 端口
然后在用ssh去连接...
可是搞不懂为啥出错了...请指教....
作者: zcheung    时间: 2011-11-14 23:07
提示为类型错误。需要整形。
你看下paramiko.SSHClient.connect原型
作者: lkk2003rty    时间: 2011-11-15 09:56
Myssh(ip1,user,pw1,pt1) ==> Myssh(ip1,user,pw1,int(pt1))
作者: fllintel    时间: 2011-11-15 17:50
回复 3# lkk2003rty


    多谢多谢 恍然大悟啊~~




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2