. Advertisement .
..3..
. Advertisement .
..4..
The error
import socket
socket.gethostbyname(socket.gethostname())
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
socket.gethostbyname(socket.gethostname())
gaierror: [Errno 8] nodename nor servname provided, or not known
occurred when I update the mac to macOS Sierra. I’ve tried to fix it for some days but have not resolved it yet. Can someone suggest a relevant solution to fix the socket.gaierror: [errno 8] nodename nor servname provided, or not known issue? Much appreciate your support.
The cause:
This error happens because you do not write the hostname in/etc/hosts in your program and you do also not determine the IP address of the host name for the local DNS configuration.
Solution:
To solve this error, you can convert your code to:
Another solution, when you use the computer name determined in /etc/hosts which have
and in your connection use “ET02282-MAC.local”, the error: ”[errno 8] nodename nor servname provided, or not known” will not exist.
There is an answer in OP’s comments based another query,, which requires that you edit
/etc/hosts
i.e.echo 127.0.0.1 $HOSTNAME >> /etc/hosts
.Alternativ, you could use
socket.gethostbyname('localhost')
assuminglocalhost
is what your need is and it is defined within your/etc/hosts
.