通过Python-cod连接PostgreSQL数据库

2024-04-25 11:41:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用Vagrant的Ubuntu虚拟机,我用vagrant upvagrant ssh设置并运行它,我创建了数据库psql -d dbname -f somesqlqueries.sql。你知道吗

每当我试图通过python通过执行conn = psycopg2.connect("dbname=dbname")连接到此数据库时,都会出现以下错误:

psycopg2.OperationalError: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?

我改变了这个问题的解决方案postgresql.conf文件但仍然会发生相同的错误。你知道吗

还尝试关闭防火墙并运行sudo ufw allow 5432/tcp,错误仍然存在。你知道吗


Tags: 数据库sqlserveronubuntuconnect错误ssh