Python on OS X: [Errno 1] Unknown host

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
./toursst: error while fetching [Errno 1] Unknown host.

I was baffled. Why is 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 ( And it worked!

First, get the local hostname by running the hostname command:

$ hostname

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 You should add a new line that looks something like this:   Raams-MacBook-Air.local

Now running the Python program works properly!

$ ./toursst
Checking feed Raam Dev

Write a Comment



  • 条件は不明だけどmacのpythonで

    [Errno 1] Unknown host