我在新系统上连接数据库时遇到问题。 Python的版本是相同的。这里是DB的连接字符串,你会看到错误信息的变化,但我无法解决为什么当连接字符串正确时我收到以下错误:
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
这是正确的连接字符串:
conn = DBAPI.connect(host='sql2', user='XXX', password='XX', database='XX', socket_timeout=100, port=5432)
当我换到不正确的地方时:
conn = DBAPI.connect(host='sql2', user='XXX', password='XX', database='XX', socket_timeout=100, port=100)
并出现以下错误消息:
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'))
我无法弄清楚这个错误消息的来源 - 看起来很古怪。我试过了:
在str()
中包裹字符串
放u'ss'
删除端口,添加套接字超时等等。
当我查看来自pg8000的core.py代码时,如果你追逐它,这似乎是来自身份验证错误。我认为这个错误(int和str)可能会使认证错误黯然失色。
AUTHENTICATION_REQUEST = b(“R”)