paramiko Error Servname not supported for ai_socktype

折月煮酒 提交于 2019-12-23 12:25:59

问题


I am unable to connect to other server through paramiko:

import paramiko
import sys
import os

hostname = 'server1'
port = 22
username = 'root'
password = 'password'`enter code here`
def deploy_key(key, hostname, username, password):
    client = paramiko.SSHClient()
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname, username, password)
    client.exec_command('mkdir -p ~/.ssh/')
    client.exec_command('echo "%s" > ~/.ssh/authorized_keys' % key)
    client.exec_command('chmod 644 ~/.ssh/authorized_keys')
    client.exec_command('chmod 700 ~/.ssh/')

key = open(os.path.expanduser('~/.ssh/id_rsa.pub')).read()
deploy_key(key, hostname, username, password)

Here was the output:

socket.AF_UNSPEC, socket.SOCK_STREAM):
socket.gaierror: [Errno -8] Servname not supported for ai_socktype

回答1:


The problem is with the call to client.connect(). It expects port to be second parameter and to be an integer, whereas you are giving username (string) as second parameter. Try replacing that with below line.

client.connect(hostname, username=username, password=password)

That should work.



来源:https://stackoverflow.com/questions/22251258/paramiko-error-servname-not-supported-for-ai-socktype

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!