Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python psycopg2.InterfaceError:仅支持协议3_Python_Django_Postgresql - Fatal编程技术网

Python psycopg2.InterfaceError:仅支持协议3

Python psycopg2.InterfaceError:仅支持协议3,python,django,postgresql,Python,Django,Postgresql,我创建了一个使用PostgreSQL(10.4版)作为数据库的软件。我还将Django用作内部API服务器。 出于某种原因。在一个没有以任何方式连接到django的代码块中(我甚至没有运行django迁移,因为我不需要从django进行任何DB查询),我得到以下错误: psycopg2.interface错误:仅支持协议3 我之所以提到django,是因为这里很多关于这个问题的问题都提到了django,所以我认为这可能会有所帮助。建议将Postgres升级到>7.4版本,正如我在上面所写的,我已

我创建了一个使用PostgreSQL(10.4版)作为数据库的软件。我还将Django用作内部API服务器。 出于某种原因。在一个没有以任何方式连接到django的代码块中(我甚至没有运行
django迁移
,因为我不需要从django进行任何DB查询),我得到以下错误:
psycopg2.interface错误:仅支持协议3

我之所以提到django,是因为这里很多关于这个问题的问题都提到了django,所以我认为这可能会有所帮助。建议将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()

你知道为什么会这样吗?网络上似乎有很多关于这个问题的问题,但没有具体的答案。

在您的self.db中,您是否提供了正确的端口?如果未提供,则默认为5432。 试着用这种方式连接
conn=psycopg2.connect(“dbname=test user=postgres password=secret port=yourport host=yourhost”)
在您的self.db中,您是否提供了正确的端口?如果未提供,则默认为5432。 试着用这种方式连接
conn=psycopg2.connect(“dbname=test user=postgres password=secret port=yourport host=yourhost”)

psycopg2的哪个版本?你从哪里获得Postgres代码的?什么版本的
psycopg2
?你从哪里得到Postgres代码的?