paramiko socket.error: Int or String expected

paramiko socket.error: Int or String expectedpython

paramiko的環境:
Python 2.6.6
paramiko==1.14.0socket

正常的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'

出現這種錯誤的狀況:code

>>> 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,能夠修復這個問題get

注意:
這個錯誤,在Python2.7.6 paramiko==1.4.0 中並無出現,其它版本,沒有作更多的測試string

相關文章
相關標籤/搜索