Rohit_chd
Rohit_chd

Reputation: 111

paramiko Error Servname not supported for ai_socktype

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

Upvotes: 10

Views: 12909

Answers (1)

Sindhura Bandi
Sindhura Bandi

Reputation: 357

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.

Upvotes: 18

Related Questions