gpt4 book ai didi

Django + Psycopg2 : InterfaceError: only protocol 3 supported

转载 作者:行者123 更新时间:2023-11-29 11:22:38 24 4
gpt4 key购买 nike

在我的 Django + Postgresql 设置中加载页面时,我偶尔会遇到此错误,但并非总是如此:

连接中的psycopg2

InterfaceError: only protocol 3 supported

psycopg2/__init__.py ? in connect

raise TypeError('missing dsn and no parameters')
else:
dsn = " ".join(["%s=%s" % (k, _param_escape(str(v)))
for (k, v) in items])
conn = _connect(dsn, connection_factory=connection_factory, async=async)
if cursor_factory is not None:
conn.cursor_factory = cursor_factory
return conn

我完全不知道是什么原因造成的。

我的 production.py 设置文件:

    DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mydbname', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'myuser',
'PASSWORD': 'mypassword',
'HOST': 'localhost', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}

最佳答案

http://initd.org/psycopg/docs/connection.html#connection.protocol_version

您没有提供您正在使用的 postgres 版本。
似乎它早于 7.4。在那种情况下,解决方案是升级 postgres 版本
(或安装旧版本的 psycopg,但我认为这不好)

关于Django + Psycopg2 : InterfaceError: only protocol 3 supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25216465/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com