Skip to main content


Showing posts from January, 2011

Python: SSL Hell

I was having a hard time getting SSL to work with gevent on Python 2.6. It turns out I had two problems. The first resulted in this error message: SSLError: [Errno 336265218] _ssl.c:337: error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib It turned out to be a permissions issue. I ran "cat" on the file, and it turned out that I didn't have access to it: cat: /etc/mycompany/certs/httpd/mycompany-wildcard.key: Permission denied I ran the command with sudo, and the problem went away. The second error was related to using urllib2 under gevent: URLError: <urlopen error [Errno 2] _ssl.c:490: The operation did not complete (read)> <Greenlet at 0x2add8d0: start_publisher> failed with URLError ... SSLError: [Errno 8] _ssl.c:490: EOF occurred in violation of protocol <Greenlet at 0x2add958: <bound method WSGIServer.wrap_socket_and_handle of <WSGIServer at 0x2b48750 fileno=3 address=>>(<socket at 0x2b48a10 fileno=5 sock

Python: use_twisted Decorator

This is a decorator that you can put on a Python function that will temporarily fire up Twisted's reactor and run a function under Twisted. This is useful if most of your program doesn't use Twisted, but you have a function that must use Twisted. Here's an example of using it: @use_twisted @defer.inlineCallbacks def do_something_twisted(): value = yield do_something_else_twisted() other_value = yield do_more_stuff() defer.returnValue(value + other_value) Here's the decorator: def use_twisted(twisted_function): """This is a decorator to run a function under Twisted. Temporarily fire up the reactor and run the function under Twisted. It should return a deferred, of course. Unfortunately, there's a bug in Twisted that only allows you to start and stop the reactor once. See Hence, this decorator will prevent you from calling it twice. So

Linux: pssh

Have you ever needed to run a bunch of shell commands over ssh on a bunch of servers? I know there are probably a ton of tools out there to do this, but when I asked my operations buddy Geoff which he preferred, he told me to try out pssh (aka parallel-ssh). I tried it, and I was pleased to discover it was easy to setup and easy to use. It's a Python package. Make sure you have setuptools installed (on Ubuntu, use "sudo apt-get install python-setuptools"). Then run "sudo easy_install pssh". It creates the following binaries in /usr/local/bin: prsync, pssh, pnuke, pslurp, pscp, and pssh-askpass. It's best if you install your ssh key on each system. I have a shell script called ssh-installkey to do that: #!/bin/sh # # Install my ssh key on a remote system. [ -n "$1" ] || { echo "usage: ssh-installkey username@host" >&2 return 1 } ssh $1 "mkdir -p -m 700 .ssh" ssh $1 "cat >> ~/.ssh/authorized_keys2&qu

Linux: Unity

I tried out Unity which is going to be the user interface for Ubuntu 11.04. It's built on top of GNOME, and it's currently used in Ubuntu's Netbook edition. Overall, I liked it. It's definitely one step closer to OS X. For instance, menus are shown at the top of the screen rather than at the top of each window. Unfortunately, I encountered several bugs when trying to use an external monitor, so clearly Canonical's programmers have their work cut out for them to hit Ubuntu's 11.04 release (due in April, of course).

Linux: CrunchBang Linux 10 on a MacBook Pro

I tried CrunchBang Linux 10 on a MacBook Pro. Previously, I had a lot of trouble dual booting with OS X, so I did the same thing I did for Ubuntu--I told it to use the entire disk. This turned out to be a big mistake. I put GRUB on the MBR since I wasn't dual booting. I also set up an encrypted LVM. The system wouldn't boot. I just got a flashing folder with a "?" icon. I think this is a known problem with Debian right now. I also wanted to try MEPIS. It's based on Debian as well. It even has a utility that you run from within OS X that sets stuff up for dual booting. Unfortunately, since I wiped OS X, that wasn't available. I was doing all this on my company's spare Macbook Pro (while my Macbook Pro was in the shop). Unfortunately, the DVD for my Macbook Pro wouldn't boot on the other Macbook Pro (which was just a few months newer). Hence, I couldn't reinstall OS X. My solution was to install Ubuntu. I gave it the whole disk, and