我已经创建了一个使用PostgreSQL (版本10.4)作为其DB的软件。我还使用Django作为内部API服务器。出于某种原因。在一个没有以任何方式连接到django的代码块中(我甚至没有运行django migrate,因为我不需要从django进行任何DB查询),我得到这个错误:psycopg2.InterfaceError: only protocol 3 supported。
我提到django的原因是这里关于这个问题的许多问题都提到了django,所以我认为它可能会有所帮助。this question建议将Postgres升级到7.4以上的版本,正如我在上面所写的,我有V10.4,它仍然在发生。
这是发生这种情况的代码:
with psycopg2.connect(**self.db) as conn: # this is where the exception occures
with conn.cursor() as cur:
cur.execute(query)
results = cur.fetchall()
if return_headers:
colnames = [desc[0] for desc in cur.description]
results.insert(0, colnames)
cur.close()你知道为什么会这样吗?网上似乎有很多关于这个问题的问题,但没有具体的答案。
发布于 2020-12-10 22:43:18
在您的self.db中,您提供的端口是否正确?如果未提供,则默认为5432。尝试以这种方式连接conn = psycopg2.connect("dbname=test user=postgres password=secret port=yourport host=yourhost")
https://stackoverflow.com/questions/65236534
复制相似问题