This is the second time I've run into this really weird issue on Mac OS X where attempting to run a Python program that uses socket.gethostname()
results in [Errno 1] Unknown host
.
In this case, I was setting up and running TouRSSt, an RSS to Maildir program:
$ ./toursst Checking feed Raam Dev Refreshing... ./toursst: error while fetching https://raamdev.com/feed/: [Errno 1] Unknown host.
I was baffled. Why is raamdev.com
an "Unknown host"?
After nearly forty minutes of Googling and looking through the code, I finally came across a suggestion to add the local hostname of my computer to my /etc/hosts
file and point it at the localhost IP address (127.0.0.1
). And it worked!
First, get the local hostname by running the hostname
command:
$ hostname Raams-MacBook-Air.local
Then add that to your /etc/hosts
(you'll need to be sudo
to edit that file) and point that hostname to the localhost IP address 127.0.0.1
. You should add a new line that looks something like this:
127.0.0.1 Raams-MacBook-Air.local
Now running the Python program works properly!
$ ./toursst Checking feed Raam Dev Refreshing...