嘿,我是数据库新手,为了方便,我决定使用Postgresql。我正在使用名为Psycopg的数据库的Python编程语言的适配器,我遵循Psycopg2的安装教程,但我得到了一个错误,所以我决定安装psycopg3,它安装成功!但是当我传递database
参数时,我得到以下错误:
Traceback (most recent call last):
File "C:UsersAdityaAppDataLocalProgramsPythonPython310libsite-packagespsycopgconninfo.py", line 97, in _parse_conninfo
return pq.Conninfo.parse(conninfo.encode())
File "psycopg_binary\pq/conninfo.pyx", line 30, in psycopg_binary.pq.Conninfo.parse
psycopg.OperationalError: invalid connection option "database"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:UsersAdityaDesktopAdityaTGbotdbhelper.py", line 3, in <module>
conn = psycopg.connect(
File "C:UsersAdityaAppDataLocalProgramsPythonPython310libsite-packagespsycopgconnection.py", line 561, in connect
conninfo = make_conninfo(**params)
File "C:UsersAdityaAppDataLocalProgramsPythonPython310libsite-packagespsycopgconninfo.py", line 56, in make_conninfo
_parse_conninfo(conninfo)
File "C:UsersAdityaAppDataLocalProgramsPythonPython310libsite-packagespsycopgconninfo.py", line 99, in _parse_conninfo
raise e.ProgrammingError(str(ex))
psycopg.ProgrammingError: invalid connection option "database"
但是当我没有传递数据库参数时,我没有得到任何类型的错误…下面是我的代码:
import psycopg
conn = psycopg.connect(
host="localhost",
database="suppliers",
user="postgres",
password="pas")
我在这里做错了什么?我确信我已经用那个名字创建了数据库,密码也是正确的。
您看起来正在使用psycopg3
。database
是psycopg2
中弃用的参数,psycopg3
中不允许使用。您需要在psycopg3
页面中为连接使用dbname
。