免费注册 查看新帖 |

Chinaunix

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

使用WINDOWS下的模块paramiko 1.7.6无法登陆SSH(py2.5) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-06-24 10:12 |只看该作者 |倒序浏览
我的PY源码如下:
import paramiko   
client = paramiko.SSHClient()   
hostname=‘192.168.1.1‘
port = '22'
username='admin'
password='123456'
if __name__=="__main__":
    client.connect(client,hostname,port,username,password)
    stdin,stdout,stderr=s.exec_command('show router ospf neighbor')
    ss=stdout.read()
    print ss
    client.close()
出错信息:
Traceback (most recent call last):
  File "D:\桌面\sshconn.py", line 8, in <module>
    client.connect(client,hostname,port,username,password)
  File "c:\python25\Lib\site-packages\paramiko\client.py", line 278, in connect
    for (family, socktype, proto, canonname, sockaddr) in socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM):
TypeError: getaddrinfo() argument 1 must be string or None


我试过了几次都是不成功登陆。
我所使用paramiko 的版本是1.7.6
说明手册如下:

connect(self, hostname, port=22, username=None, password=None, pkey=None, key_filename=None, timeout=None, allow_agent=True, look_for_keys=True)  source code   

Connect to an SSH server and authenticate to it. The server's host key is checked against the system host keys (see load_system_host_keys) and any local host keys (load_host_keys). If the server's hostname is not found in either set of host keys, the missing host key policy is used (see set_missing_host_key_policy). The default policy is to reject the key and raise an SSHException.

Authentication is attempted in the following order of priority:

•The pkey or key_filename passed in (if any)
•Any key we can find through an SSH agent
•Any "id_rsa" or "id_dsa" key discoverable in ~/.ssh/
lain username/password auth, if a password was given
If a private key requires a password to unlock it, and a password is passed in, that password will be used to attempt to unlock the key.

Parameters:
•hostname (str) - the server to connect to
•port (int) - the server port to connect to
•username (str) - the username to authenticate as (defaults to the current local username)
•password (str) - a password to use for authentication or for unlocking a private key
•pkey (PKey) - an optional private key to use for authentication
•key_filename (str or list(str)) - the filename, or list of filenames, of optional private key(s) to try for authentication
•timeout (float) - an optional timeout (in seconds) for the TCP connect
•allow_agent (bool) - set to False to disable connecting to the SSH agent
•look_for_keys (bool) - set to False to disable searching for discoverable private key files in ~/.ssh/
Raises:
•BadHostKeyException - if the server's host key could not be verified
•AuthenticationException - if authentication failed
•SSHException - if there was any other error connecting or establishing an SSH session
•socket.error - if a socket error occurred while connecting

论坛徽章:
0
2 [报告]
发表于 2010-06-24 15:21 |只看该作者

论坛徽章:
0
3 [报告]
发表于 2010-06-25 00:19 |只看该作者
我已经知道原因了,是因为SSH V2第一次连接是,是需要保存对方的PUB  KEY(也就是KNOW  HOST信息)那这个HOST我要如何获取并保存呢?

论坛徽章:
0
4 [报告]
发表于 2010-06-26 10:07 |只看该作者
有人能帮一下不?

论坛徽章:
0
5 [报告]
发表于 2010-06-26 10:46 |只看该作者
本帖最后由 luffy.deng 于 2010-06-26 10:47 编辑

如果是pub key 问题 这里http://hi.baidu.com/hiddb/blog/item/295e683cf8811209bba16765.html这篇文章说set_missing_host_key_policy(paramiko.AutoAddPolicy()) 。对pgp不熟 不知道是否管用。

论坛徽章:
0
6 [报告]
发表于 2010-06-26 11:15 |只看该作者

我已解决了此问题。答案正如楼上如答。谢谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP