[ACCEPTED]-Why am I getting socket.gaierror: [Errno -2] from Python HTTPLib-sockets

Accepted answer
Score: 16

The socket.gaierror comes from Python not being able to 16 run getaddrinfo() or getnameinfo(). In your case it is likely the 15 first one. That function takes a host and 14 a port and returns a list of tuples with 13 information about how to connect to a host. If 12 you give a host name to that function there 11 will be a try to resolve the IP address 10 deeper below.

So, the error should come from 9 Python not being able to resolve the address 8 you have written (yun.local) to a valid IP address. I 7 would suggest you look in /etc/hosts on the device 6 to see if it is defined there. You can also 5 try with command line tools such as host or 4 telnet, just to check the resolving:

For example:

[pugo@q-bert ~]$ telnet localhost 80
Trying ::1...
telnet: Unable to connect to remote host: Connection refused

There 3 it managed to resolve my localhost to ::1 (IPv6) and 2 (IPv4), because it exists in /etc/resolv.conf. If I instead 1 try with your host:

[pugo@q-bert ~]$ telnet yun.local 80
telnet: could not resolve yun.local/80: Name or service not known
Score: 0

In my case, I changed the hostname. So I 4 realized the /etc/hosts remained the old 3 hostname, I just updated to the new hostname 2 in the /etc/hosts file and that worked for 1 me.

More Related questions