469,282 Members | 1,708 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

How do I fix "socket.gaierror: [Errno -2] Name or service not known" when using paramiko?

I am trying to send an email in my python script via ssh. However, I keep getting
Expand|Select|Wrap|Line Numbers
  1. socket.gaierror: [Errno -2] Name or service not known
.
I searched google for it and found this: https://stackoverflow.com/questions/...vice-not-known, but that doesn't solve the problem, as I can connect like normal to the server using a terminal, only in Python it's not working.
I also found this source: https://www.programcreek.com/python/...ocket.gaierror, but a simple try-except won't help, if the code *always* runs into this error, not just occasionally.

The code I use:
Expand|Select|Wrap|Line Numbers
  1. import paramiko
  2. hostname, sshport, username, password = splitLine
  3.             print(splitLine)
  4.             ssh = paramiko.SSHClient()
  5.             ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  6.             ssh.connect(hostname, port=int(sshport), username=username, password=password)
  7.  
splitLine is a line I read from a txt-File beforehand, looking like this (with actual data of course):
Expand|Select|Wrap|Line Numbers
  1. my_server_adress port username password
  2.  
It is preformatted and then split into a python list: ["my_server_adress", "port", "username", "password"].
I also tried the port with and without conversion to an integer, get the same error both times.
Aug 9 '21 #1
0 2267

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by hanjar | last post: by
2 posts views Thread by flamesrock | last post: by
1 post views Thread by sa6113 | last post: by
4 posts views Thread by sa6113 | last post: by
reply views Thread by sa6113 | last post: by
reply views Thread by sa6113 | last post: by
reply views Thread by sa6113 | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.