In the end of makeConnection, in postgres/pg_connection.py, the method 'query' is called on the connection object.
The connection object has just been created using a call to one or another DB API constructors, and the DB API spec does not have a 'query' method. As far as I know, the psycopg2 implementation does not have such a method either.
I patched my copy by adding an hasattr call to verify the existence of 'query' method, but I suspect a better fix is to use method is .execute, so the end of makeConnection would be:
dbEncoding = self.dbEncoding
if dbEncoding: # and hasattr(conn,'query'):
conn.execute("SET client_encoding TO %s",dbEncoding)