3

When I run the following command to get the host ip:

socket.gethostbyname(socket.gethostname())

I am getting the following error on MAC terminal:

socket.gaierror: [Errno 8] nodename nor servname provided, or not known

Any idea what the problem could be?

socket.gethostname() does return the correct hostname.

4
  • have you tried to pass socket.gethostname().strip() ? Commented May 2, 2013 at 6:56
  • yes I tried that but it didn't help Commented May 2, 2013 at 6:58
  • if you try to ping (from command line) the host that socket.gethostname() returns, does it say unknown host? Commented May 2, 2013 at 7:03
  • that's right. it does say unknown host! any idea what would cause that? thanks! Commented May 2, 2013 at 7:06

1 Answer 1

3

Try to open as root /etc/hosts file, and add a line like the following

# IP ADDR      HOSTNAME
192.168.1.1    your_desired_hostname

and the name should resolve.

Obviously substitute 192.168.1.1 with your ip address.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.