This project is archived and is in readonly mode.
it stammers on error "could not connect"
Reported by flox | November 5th, 2011 @ 10:54 PM
When it resolves the hostname, the error message is
duplicated.
When you pass an IP address, the error message is correct.
(Ubuntu 64 bits)
>>> print __import__('sys').version
2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
[GCC 4.4.5]
>>>
>>> import psycopg2 as pg
>>> print pg.__version__
2.4.2 (dt dec pq3 ext)
>>>
>>> pg.connect('host=localhost')
Traceback (most recent call last):
File "<console>", line 1, in <module>
OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" and accepting
TCP/IP connections on port 24004?
could not connect to server: Connection refused
Is the server running on host "localhost" and accepting
TCP/IP connections on port 24004?
>>> pg.connect('host=127.0.0.1')
Traceback (most recent call last):
File "<console>", line 1, in <module>
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 24004?
>>>
Comments and changes to this ticket
-
flox November 6th, 2011 @ 01:33 AM
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 November 16th, 2011 @ 10:11 AM
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 localhost6
can 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 November 16th, 2011 @ 11:54 PM
- 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 November 17th, 2011 @ 08:52 PM
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
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="https://github.com/psycopg/psycopg2/issues">the new tracker</a>.
<br/>
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.