Blog Entries tagged django
Feeds: RSS | Atom

PostgreSQL/Python/psycopg2: Confusing error, port setting required for socket connections

Published: 2010-02-06 13:43 UTC. Tags: django python

When trying to get my local development copy of this website running after upgrading my Ubuntu, I got the following confusing error message from the psycopg2 python module:

psycopg2.OperationalError: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket  "/var/run/postgresql/.s.PGSQL.5432"?

My django settings file was correct:

DATABASE_ENGINE = 'postgresql_psycopg2'  # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'dbname'                 # Or path to database file if using sqlite3.
DATABASE_USER = 'dbuser'                 # Not used with sqlite3.
DATABASE_PASSWORD = 'dbpassword'         # Not used with sqlite3.
DATABASE_HOST = ''                       # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''                       # Set to empty string for default. Not used with sqlite3.

Confusing, since my Postgres server was running and I could connect using psql:

psql -U dbuser -W dbname

This turned out to be one of these problems when Google is of no help - others had the same problem, but I could only find posts where people asked the question, no posts where the actual solution was found.

The cause of the problem was that my PostgreSQL installation was configured to listen on port 5433 instead of the default 5432, and as seen in the error message, the port number is part of the path to the unix socket. The different port was probably setup when I upgraded my Ubuntu, since that installed PostgreSQL 8.4 without completely removing PostgreSQL 8.3. The latter is configured to listen on the default port.

The solution is to either configure the running PostgreSQL to listen on port 5432 by modifying /etc/postgresql/8.4/main/postgresql.conf, or by modifying the Django configuration by setting the port:


Weird Django Bug

Published: 2008-12-04 17:36 UTC. Tags: software django

I think I hit Django bug #6681 yesterday. It's the kind of bug that triggers only if three completely different conditions are met at the same time, where at least one of them depends on timing. In this case:

  • The Apache process must be recently started.
  • The first request hitting the Apache process must be for a page that requires reST rendering.
  • The reST must have a section that triggers the default interpreted role.

For reference, the exception was:

AttributeError: Values instance has no attribute 'default_reference_context'

Migrating Plone Sites to Django

Published: 2008-11-01 20:50 UTC. Tags: software plone django noplone

As mentioned earlier on this blog, I have converted this site from Plone to Django.

The conversion included migrating most of the data from the Plone instance's ZODB (Zope Object Database) into Django's ORM.

The hard part of that process is to get the data out of ZODB as the format depends completely on which Plone products you have been using. You need to check the schema for each product for which you want to extract data to get the field names, and you need to write code for extracting the data from each type of content type and add a new object in Django's ORM, translating data from one format to another in some cases.

In my case, I wrote a script that takes care of:

  • Document and Folder objects from Plone's standard contenttypes.
  • Blog entries in a Quills blog.

The script will traverse all Document, Folder and Blog entries and extract their data, adding instances of Django models from two custom Django products I have written.

A second script will then read the data from Django's database and modify the URLs in <img> tags, downloading the images from the Plone site via HTTP to a directory which will be configured as MEDIA_ROOT in Django. The script does the same for <a> tags that refer to images, .tar.gz files, etc. that also were stored in the ZODB of the Plone instance.

Each site that wants to do a conversion from Plone to Django will have to write their own script, as the set of products used in the Plone instance is site-specific, and the set of applications used in Django is also site-specific. However, I have made my conversion scripts available via subversion in the hope that they can serve as an example.

To access the scripts, either check them out with your subversion client. Example:

git clone git://

The scripts are in the plone2django_migration subdirectory.

You can also browse them here:


ViewVC Django Integration

Published: 2008-10-25 20:14 UTC. Tags: open source software django version_control

I've written a Django product which helps integrating ViewVC in a Django Site.


Feed Fixed. Site Todo.

Published: 2008-09-22 19:00 UTC. Tags: django

Yesterday evening was one of those frantic hacker moments when you really really want to get the piece of software you've been working on for a while up and running, even if it's getting really late and you know you have to get up early the next morning. The broken feed, showing pseudo-HTML to the user, was one effect of that. Has now been fixed by use of the safe filter tag.

One interesting thing is that Google Reader thought all my entries were new, even though I made sure the timestamps in the RSS were identical. Might have had to do with the change of the GUID-values in the feed, from a $£@¡$£!! plone probably archetypes-hexadecimal thingie into the KISS solution - the URL to the entry. Planet Lysator seems to have behaved correctly, displaying only the new entry.

Lot's of stuff still on the todo for this site, for example:

  • Better Navigation.
  • Catchier frontpage.
  • Photo album integrated with rest of site, to make it easy to link to photos from other kinds of content. A Photo feed, perhaps?
  • Make code for site available to the world.
  • A blog entry on how I converted from Plone to Django. Make conversion code available to the world - Done.
  • Some kind of more or less automatic moderation of comments, I've already received some spammy ones.
  • Preview in edit-mode when writing blog and CMS/content entries in reST.
  • A blog entry on why I've switched from Plone to Django..

All of this have to wait for another day, because now is time to sleep.


Bye Bye Plone, Hello Django!

Published: 2008-09-21 20:18 UTC. Tags: plone django noplone

This is the first post on the rewritten, now running a set of django apps instead of Plone. Yay!

Now let's hope everything works as I want them to. More info follows.