Your browser is very old. You might enjoy surfing the web more if you used something newer like:

Google Chrome

Even Firefox would be OK.

If you're being forced at gunpoint to use Internet Explorer, you should at least upgrade it. Version 8 is tolerable and 9 will be OK when it comes out.

Posts from June 2009

Getting started with CherryPy

I mentioned briefly last week that I was getting started with CherryPy and how impressed I was with the ease of the install. I also finally figured out that Ubuntu has a psycopg package (python-psycopg), although I still couldn’t get web.py to work with it.

Here’s a list of the packages that I had to install on my Ubuntu 9.0.4 server to get CherryPy running

apt-get install python
apt-get install python-setuptools
apt-get install flup
apt-get install postgres
apt-get install postgresql postgresql-client postgresql-contrib
apt-get install pgdb
apt-get install postgresql-python
apt-get install python-pygresql
apt-get install gcc
apt-get install g++
apt-get install postgresql-dev
apt-get install libpq-dev
apt-get install python-psycopg

Want to get a “Hello World” example of CherryPy working? It’s incredible easy, especially if you use CherryPy’s built-in webserver (which seems like it’ll handle the sort of loads I’m going to be dealing with).

Here’s the code:

import cherrypy

cherrypy.config.update( {'server.socket_host': '127.0.0.1',
                        'server.socket_port':  80,
                        })

class HelloWorld:
        def index(self):
            return "Hello World"
        index.exposed = True

cherrypy.quickstart(HelloWorld())

Then, as root, run the following command to start the built-in webserver (assuming the code above is in the file /var/www/hello.py):

python /var/www/hello.py

If all goes well, you should see something like this:

[16/Jun/2009:21:08:00] ENGINE Listening for SIGHUP.
[16/Jun/2009:21:08:00] ENGINE Listening for SIGTERM.
[16/Jun/2009:21:08:00] ENGINE Listening for SIGUSR1.
[16/Jun/2009:21:08:00] ENGINE Bus STARTING

Go to http://localhost in your browser and you should see the text “Hello World.”

And here’s a quick database example that connects to a PostgreSQL database called testdb with a single table called todo.

CREATE TABLE todo (
    id integer NOT NULL,
    title text,
    created timestamp without time zone DEFAULT now(),
    done boolean DEFAULT false
);

INSERT INTO todo (id, title, created, done) VALUES (1, 'Learn CherryPy', '2009-06-15 11:31:38.106307', false);
import cherrypy
import psycopg
import sys

cherrypy.config.update( {'server.socket_host': '10.0.0.4',
                        'server.socket_port':  80,
                        })

class HelloWorld:
        def index(self):
            conn = psycopg.connect('dbname=testdb', 'user=myuser', 'password=mypass')
            mark = conn.cursor()
            mark.execute('SELECT * FROM todo');
            rec = mark.fetchall()

            body = ''
            for row in rec:
                body += str(row)

            return body
        index.exposed = True

cherrypy.quickstart(HelloWorld())

That’s a very basic intro to CherryPy. The complete documentation has lots of great stuff and I’ll be back to write more about it after I’ve had a chance to write something real.

Installing things on Linux is still a pain in the tuchus

I’ve been trying like mad to get web.py working over the last week. Getting the initial dependencies and base install was straightforward enough but now I’m stuck.

I can’t get web.py to connect to Postgres using whatever the built-in Python DB library is and I can’t get psycopg2 installed because of an endless series of bizarre errors. The documentation for both web.py and psycopg is less than stellar.

So I’m giving up.

I hope this makes every Linux developer out there shudder. How many people are dumping your software because they can’t figure out how to install the freaking thing?

Yes, I know things have drastically improved with the various package systems out there. Yes, I know the Linux ecosystem is more complicated to handle installation for.

Guess what? I don’t give a shit.

I don’t want to waste a week just trying to get a piece of software to run. I want to write code.

And that’s why I’ve switched over to CherryPy. The base install, including DB support, was one step and took me all of 5 minutes to do. Now I can get down to my primary goal of doing something fun in Python.

So, to all you Open Source projects out there, you’re awesome and I love you! But you’ve got to spend more time on documentation and making installation easier if you want your project to really succeed.

*Yes, I know the install process on OSX is generally really good but, at this point, I still have more Windows experience to speak to.

Facebook’s OpenID Support: Much Improved!

I decided to give linking my Facebook account to my OpenID delegate page another go last night.

Lo and behold, it still didn’t work. But this time, I got a useful error message!

Facebook Error Message

After some Googling and reading, I finally figured out that I needed to add the following two lines to the source of my delegate page. Now I have a delegate page that works with OpenID 1.1 and OpenID 2.0.



Once I got that, I was able to link Facebook to my MyOpenID account. The weird logging in and out issues I reported a couple of weeks ago also seem to be resolved.


<html>
    <head>
        <!-- OpenID 2.0 delegate information -->
        <link rel="openid2.provider" href="http://www.myopenid.com/server" />
        <link rel="openid2.local_id" href="http://yourusername.myopenid.com/" />

        <!-- OpenID 1.1 delegate information -->
        <link rel="openid.server" href="http://www.myopenid.com/server" />
        <link rel="openid.delegate" href="http://yourusername.myopenid.com/" />
    </head>
    <body>
    </body>
</html>