免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2515 | 回复: 3
打印 上一主题 下一主题

错在哪? 新手指教 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 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去连接...
可是搞不懂为啥出错了...请指教....

论坛徽章:
0
2 [报告]
发表于 2011-11-14 23:07 |只看该作者
提示为类型错误。需要整形。
你看下paramiko.SSHClient.connect原型

论坛徽章:
0
3 [报告]
发表于 2011-11-15 09:56 |只看该作者
Myssh(ip1,user,pw1,pt1) ==> Myssh(ip1,user,pw1,int(pt1))

论坛徽章:
0
4 [报告]
发表于 2011-11-15 17:50 |只看该作者
回复 3# lkk2003rty


    多谢多谢 恍然大悟啊~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP