This project is archived and is in readonly mode.
it stammers on error "could not connect"
-
flox
It's even worse on the @devel branch
>>> import psycopg2 as pg >>> print pg.__version__ 2.4.3.dev0 (dt dec pq3 ext) >>> pg.connect('host=localhost') Traceback (most recent call last): File "<stdin>", line 1, in <module> psycopg2.OperationalError: could not connect to server: Connection refused Is the server running on host "localhost" and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" and accepting TCP/IP connections on port 5432? >>> pg.connect('host=127.0.0.1') Traceback (most recent call last): File "<stdin>", line 1, in <module> psycopg2.OperationalError: could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432? -
Daniele Varrazzo
This is just what is passed us by the libpq: it probably depends on what you have in the hosts file. What I get on my box recently switched to ubuntu 11.10 is:
>>> cnn = psycopg2.connect('host=localhost port=5431') OperationalError: could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5431? could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5431?My hosts file says::
127.0.0.1 localhost.localdomain localhost ::1 bagheera localhost6.localdomain6 localhost6can you try on your box to play a little with the /etc/hosts configuration, to see if the message changes, or to add a printf statement at connection to check the error message returned by the libpq? I say that's what the libpq says and is not mangled by psycopg. If i'm wrong I'll fix it, otherwise you should hear from the postgres developers.
-
Daniele Varrazzo
- State changed from new to invalid
Please test applying the following patch:
diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index 441d362..5aab2ea 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -542,6 +542,7 @@ _conn_sync_connect(connectionObject *self) else if (PQstatus(pgconn) == CONNECTION_BAD) { Dprintf("conn_connect: PQconnectdb(%s) returned BAD", self->dsn); + fprintf(stderr, "START\n%s\nEND\n", PQerrorMessage(pgconn)); PyErr_SetString(OperationalError, PQerrorMessage(pgconn)); return -1; }compile and try to connect to the wrong port. If you get a "stammering error" on stdout between a single pair START/END, it means that it is the libpq to stammer (but as you see from my output it could be that it is actually trying to open the connection in different ways). If you see several START/END pairs, it is our bug.
Closing the bug unless further evidence is provided.
-
flox
Right, it seems that this message comes from libpq.
I see that the message you have is more informative than the one I got: it shows which IP is tried on each tentative.
Probably I don't use the same version of libpq as you.
-- Florent