paramiko socket.error: Int or String expected

paramiko socket.error: Int or String expected

paramiko的环境:
Python 2.6.6
paramiko==1.14.0

正常的paramiko用法:

>>> import paramiko
>>> client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('10.2.1.243', port=22, username='root', password='', timeout=600) 
stdin, stdout, stderr = client.exec_command('pwd')>>> client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> client.connect('10.2.1.243', port=22, username='root', password='', timeout=600) 
>>> stdin, stdout, stderr = client.exec_command('pwd')
>>> stdout.read()
'/root\n'

出现这种错误的情况:

>>> import paramiko
>>> client = paramiko.SSHClient()
>>> client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> port=22L
>>> client.connect('10.2.1.243, port=port, username='root', password='', timeout=600) 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/project/maintain/lib/python2.6/site-packages/paramiko/client.py", line 222, in connect
    for (family, socktype, proto, canonname, sockaddr) in socket.getaddrinfo(hostname, port, socket.AF_UNSPEC, socket.SOCK_STREAM):
socket.error: Int or String expected

上面这个错误,是因为connect方法中的port设置为Long int了,把port转为string或者int,可以修复这个问题

注意:
这个错误,在Python2.7.6 paramiko==1.4.0 中并没有出现,其它版本,没有做更多的测试

你可能感兴趣的:(socket)