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

Alert to All Mac OS X Users: Protect Yourself from CVE-2008-5353!

Update: TidBITS writes that Apple has released a patched version of Java that fixes this issue. It is available through Software Update.

CVE-2008-5353 is a critical Java vulnerability that was discovered back in August 2008 and patched by Sun Microsystems a few months later. However, Apple has failed to release a patched version of Java, even in the latest 10.5.7 update! CVE-2008-5353 is described as follows:

Unspecified vulnerability in Java Runtime Environment (JRE) for Sun JDK and JRE 6 Update 10 and earlier; JDK and JRE 5.0 Update 16 and earlier; and SDK and JRE 1.4.2_18 and earlier allows untrusted applets and applications to gain privileges via unknown vectors related to "deserializing calendar objects."

Since Apple failed fix this vulnerability in the latest update to OS X (10.5.7), Landon Fuller, a programmer and former Apple Engineer, released a proof-of-concept demonstrating the exploit. The demonstration is done by launching a Java applet in your web browser and using the exploit to run the /usr/bin/say command on your Mac to "speak" some words through your speakers. This may not sound very dangerous, but this same exploit could be used to run malicious code on your Mac without your even knowing it!

So, how can I protect myself?

For now, all you can do is entirely disable Java in your browsers to ensure no Java applets are allowed to run. The good news is that chances are you probably don't depend on Java anyway (remember, Java is not JavaScript). And if you find yourself needing to run something that does require Java (the browser will alert you with a message saying the Java plugin isn't installed), you can always re-enable Java in your browser while you're using the applet, and then disable it again when you're done. Inconvenient, yes, but worth it. This is one nasty vulnerability, and with all the publicity it's been getting lately, there's bound to be more malicious code in the wild just waiting to hijack your system.

Disabling Java in Firefox

In Firefox, choose from the menu, Firefox -> Preferences. Then select the Content tab and un-check the Use Java option:

Firefox Content Preferences, Use Java option

Disabling Java in Safari

(applies to both Safari 3 and Safari 4 Beta)

In Safari, choose from the menu, Safari -> Preferences. Then select the Security tab and un-check the Enable Java option:

Safari 4 Beta Security Preferences, Enable Java option

Update: TidBITS writes that Apple has released a patched version of Java that fixes this issue. It is available through Software Update.

Ripping and Converting DVDs to MPEG-4 on Mac OS X

I've been converting a lot of my DVDs to MPEG-4 recently. The process is much easier than I always imagined, so I decided to explain the procedures I use here. All of this is done on my Mac, so the directions are somewhat Mac-specific. That said, HandBrake (the main application used in this process) is open-source and available on Windows and Linux. You should be able to find MacTheRipper-equivalents for Windows and Linux (and if you know of some, please mention them in the comments!).

Download & Install Software

  1. Download MacTheRipper (v2.6.6 is listed on that site but I'm using v3.0. Search BitTorrent for the newer version if you're interested.)
  2. Download HandBrake (I'm using v0.9.3)
  3. Install the above applications

Rip the DVD Using MacTheRipper (what an awesome name!)

  1. Insert the DVD
  2. OS X will automatically start playing the DVD. Press CMD+Q to quit the application.
  3. Launch MacTheRipper (and be careful he doesn't hurt you)
  4. MacTheRipper

  5. Leave the default options and select File -> Save To...
  6. Create a new directory to temporarily store the raw contents of the DVD and select it
  7. Click Open. MacTheRipper will automatically start ripping the raw contents of the DVD to the directory you selected
  8. When the ripping finishes, quit MacTheRipper

Convert the Raw DVD Data to MPEG-4 Using HandBrake

  1. Launch HandBrake (don't break your hand)
  2. Upon launching, you should be presented with the Open dialog. You want to select the directory to which you ripped the DVD using MacTheRipper. Note: Select the directory that contains the VIDEO_TS directory, but not VIDEO_TS directory itself! The other directories contain important data, such as AUDIO_TS for audio data.
  3. Click Open and HandBrake will scan the various titles in the raw data. When finished, you'll be left with the main HandBrake screen
  4. HandBrake Main Screen

  5. The correct title should already be selected and it should be the longest one in the list. If it's a 2-hour DVD, you don't want to select the title that says 1 minute. There may be lots of short titles mixed in and these may be extras on the DVD or previews.
  6. After you've selected the correct title, choose browse and select a location where you want to save the converted video. After selecting the location, you can change the filename or leave the default. I like to store various bits of information in the video filename, such as the year the video was released, whether it's widescreen or full screen, and the codec and audio formats. For example:


  7. Now select the format. I usually choose AVI for the best compatibility.
  8. For video codec, choose "MPEG-4 (XviD)"
  9. Next to "Quality:", select "Target size (MB)" and use the following guidelines. I like to retain as much of the quality as possible, so I follow these rules. Remember, the higher the file size, the better the quality. If you don't care so much about quality or don't have lots of free space, you can just use 700MB for DVDs. I use 1400MB for DVDs, and smaller sizes for TV/Documentary or episodic movies.

    Here are the sizes I use depending on the length of the movie or episode:

    175MB (20-30 mins)
    350MB (40-55 mins)
    1400MB (90 min+), also known as 2CD quality

  10. Click the "Audio & Subtitles" tab
  11. Choose the best audio source quality available. Sometimes the DVD will contain 6-Channel 5.1 audio, but it won't be selected by default.
  12. If it's available, select "AC3 Passthru" under "Audio Codec".
  13. HandBrake Audio Settings

  14. With everything configured, click Start. If you're converting a DVD that is a collection of shorter movies (like the Outer Limits DVD I'm ripping in the example), you can simply click "Add to Queue", repeat the above process for each of the titles, and then click Start when everything is queued up. If you plan to do this though, you should definitely convert at least one episode first to make sure it comes out correct.

Depending on the speed of your computer, the quality, and the length of the movie you're converting, this process could take anywhere from 30 minutes to 3 hours.

When HandBrake finishes, try watching the resulting AVI and make sure it plays correctly (with sound and all). If you're not happy, delete it and repeat the process again. Once you're happy with the AVI, you can delete the raw data that you ripped earlier with MacTheRipper (it takes up 6-7GB of space!).

HOWTO: Make iTunes Read Ogg Files

After downloading the only available torrent of Hang Drum music I could find, I was shocked to discover that iTunes wouldn't read the Ogg files it contained. I was so close to losing a ton of respect for Apple until I searched Google for a solution. Hooray for the open-source community! Simply visit their site and download QuickTime Components binary package. After opening the .dmg file (Windows users should be able to just download and run the .exe file), copy XiphQT.component to ~/Library/Components (user-only) or to /Library/Components (system-wide).

Update: Randy Cox noted in the comments that on Snow Leopard the path to copy the file is actually /Library/Quicktime/ If iTunes is open, restart it and viola! You've got .ogg support in iTunes!

HOWTO: Install md5sum & sha1sum on Mac OS X

I was a bit surprised to learn that my Mac didn't have the md5sum and sha1sum tools installed by default. A quick search and I found a site that provides the source. The sources compiled successfully on my Mac (OS X 10.5.5, xCode tools installed).

The only quirk appears in the last step:

$ ./configure
$ make
$ sudo make install
cp md5sum sha1sum ripemd160sum /usr/local/bin
chown bin:bin /usr/local/bin/md5sum /usr/local/bin/sha1sum
chown: bin: Invalid argument
make: *** [install] Error 1

The make install command tries to change the ownership of the files to the bin user. Since that user doesn't exist on my system, the command fails. This isn't a problem though, as both binaries work perfectly. By default, they are installed to /usr/local/bin/.

Using the OS X md5 instead of md5sum

As a commenter pointed out, the /sbin/md5 utility provided by OS X contains a hidden -r switch that causes it to output in a format identical to that of md5sum, making it compatible with scripts that require md5sum's format. If you want to use the md5 utility provided by OS X, you can add the following to your ~/.profile or ~/.bashrc:

alias md5='md5 -r'
alias md5sum='md5 -r'

Installing with HomeBrew

A commenter mentioned that you can install md5sum using HomeBrew by running brew install coreutils.

Update (2015-02-25): The current method for installing via HomeBrew is as follows:

brew install md5sha1sum

Installing with MacPorts

A commenter mentioned if you have MacPorts installed, you can run port install coreutils but "you’ll need to add /opt/local/libexec/gnubin/ to your PATH.

Update (2014-08-25): It appears that you should use sudo port install md5sha1sum.