Use psycopg2 instead of pgsql
conn = psycopg2.connect( host=host, dbname=dbname, user=user, password=password )