psycopg2.OperationalError: 致命: 不支持的前端协议 1234.5679: 服务器支持 2.0 到 3.0 [英] psycopg2.OperationalError: FATAL: unsupported frontend protocol 1234.5679: server supports 2.0 to 3.0

查看:40
本文介绍了psycopg2.OperationalError: 致命: 不支持的前端协议 1234.5679: 服务器支持 2.0 到 3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Macbook

I'm using Macbook

Psycopg2 在连接本地主机数据库(Mac 上的 PostgreSQL)时运行良好.当我尝试在 Windows10 上连接 PostgreSQL 数据库时出现错误.

Psycopg2 works well when connecting the localhost db (PostgreSQL on Mac). The error was raised when I tried to connect PostgreSQL db on a Windows10.

下面的代码是我用来连接的,主机就是windows10的IP

the following code is what I have for connection, the host is just the IP of the windows10

db= psycopg2.connect(database='dbname',user='username',password="secret",host="192.168.3.9",port="5432")

错误:

  File "path/to/psycopg2/__init__.py", line 126, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL:  unsupported frontend protocol 1234.5679: server supports 2.0 to 3.0

这是因为系统兼容性还是其他原因?我试过其他 Windows 机器,但我没有运气让它工作.但是,当我使用 Node.JS 模块 pg

Is this because of system compatibility or something else? I've tried other Windows machine and I got no luck to make it work. However, I was able to connect PostgreSQL on windows while I using Node.JS module pg

推荐答案

1234.5679 是客户端发送的特殊代码,用于请求 SSL 加密的数据库连接,并且自 PostgreSQL 开始支持提交 e0e7daef6da 于 1999 年.但是你的 PostgreSQL 不能那么旧,因为 2003 年之前没有添加对协议版本 3.0 的支持.

1234.5679 is the special code sent by the client to request SSL-encrypted database connections, and support for that has been in PostgreSQL since commit e0e7daef6da in 1999. But your PostgreSQL cannot be that old, because support for protocol version 3.0 was not added before 2003.

其实从研究src/backend/postmaster/postmaster.c和看邮件列表来看,这是PostgreSQL服务器的一个bug:

Actually, from studying src/backend/postmaster/postmaster.c and reading the mailing list, this is a bug on the PostgreSQL server:

客户端必须配置为尝试 GSS 身份验证,当服务器拒绝时,它想协商 SSL 连接,但此时服务器并不期望;因此错误.

The client must be configured to try GSS authentication, and when the server rejects, it wants to negotiate an SSL connections, but the server doesn't expect that at this point; hence the error.

查看讨论此处.该错误已在 12.3 版中修复.

See the discussion here. The bug has been fixed with release 12.3.

作为一种解决方法,禁用客户端上的 GSS 身份验证或 SSL 协商.

As a workaround, disable either GSS authentication or SSL negotiation on the client.

在 psycopg2 中,禁用 SSL 是通过在连接字符串中使用 sslmode="disable" 来完成的,而禁用 GSS 是使用 gssencmode="disable" 来完成的.有关详细信息,请参阅文档.

In psycopg2, disabling SSL is done by using sslmode="disable" in the connection string, and disabling GSS is done with gssencmode="disable". See the documentation for details.

这篇关于psycopg2.OperationalError: 致命: 不支持的前端协议 1234.5679: 服务器支持 2.0 到 3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆