1

I'm having trouble connecting to a db on a new system. The version of Python is the same. Here is the connection string for the DB that is there and you'll see the error message change, but I cannot work out why when the connection string is correct I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pg8000/__init__.py", line 148, in connect
    user, host, unix_sock, port, database, password, socket_timeout, ssl)
  File "/usr/local/lib/python2.7/dist-packages/pg8000/core.py", line 1157, in __init__
    raise exc_info()[1]
TypeError: cannot concatenate 'str' and 'int' objects

Here is my connection string when correct:

conn = DBAPI.connect(host='sql2', user='XXX', password='XX', database='XX', socket_timeout=100, port=5432)

and when I change to something incorrect:

conn = DBAPI.connect(host='sql2', user='XXX', password='XX', database='XX', socket_timeout=100, port=100)

and the following error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/opt/Centos5.8/python-2.7.4_scipy0.13/lib/python2.7/site-packages/pg8000/__init__.py", line 148, in connect
    user, host, unix_sock, port, database, password, socket_timeout, ssl)
  File "/mnt/opt/Centos5.8/python-2.7.4_scipy0.13/lib/python2.7/site-packages/pg8000/core.py", line 854, in __init__
    raise InterfaceError("communication error", exc_info()[1])
pg8000.errors.InterfaceError: ('communication error', error(111, 'Connection refused'))

I cannot figure out where this error message is coming from - it seems bizzare. I've tried:

wrapping string in str() putting u'ss' removing port, adding socket-timeout etc etc.

When I looked in the core.py code from pg8000 it appears that this comes from an authentication error if you chase it through. I think this error (int and str) might be eclipsing the authentication error.

Message codes

AUTHENTICATION_REQUEST = b("R")

disruptive
  • 5,687
  • 15
  • 71
  • 135
  • Have you tried wrapping the `socket_timeout` and `port` values in `str()` individually? – TheSoundDefense Jul 16 '14 at 15:27
  • @TheSoundDefense, need socket_timeout and port as integer - I tried wrapping. host=str(dbsettings['host']), user=str(dbsettings['user']), password=str(dbsettings['password']), database=str(dbsettings['database']), port=dbsettings['port'], ssl=dbsettings['ssl'] – disruptive Jul 16 '14 at 16:21

1 Answers1

6

This is a bug in pg8000. It was fixed in pg8000-1.9.11. The bug is an error in reporting the error that pg8000 encountered while trying to authenticate against the database.

Peter Vandivier
  • 606
  • 1
  • 9
  • 31
Tony Locke
  • 454
  • 3
  • 9
  • I changed to the updated code and now I get a proper error: pg8000.errors.InterfaceError: Authentication method 3 not supported by pg8000. – disruptive Jul 21 '14 at 12:13
  • Method 3 is plain text password authentication. I think pg8000 should support it, so I've created a feature request at https://github.com/mfenniak/pg8000/issues/52. – Tony Locke Jul 24 '14 at 20:43