Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting psycopg.ProgrammingError: invalid connection option "database" when pasing database parameter

Hey I am new to Databases and I decided to use Postgresql for convinience. And I am using an adapter for the Python programming language of the database named Psycopg I followed the installation tutorial of Psycopg2 but I was getting an error so I decided to install psycopg3 and it installed successfully! but when I pass the database parametere I get the following error:

Traceback (most recent call last):
  File "C:\Users\Aditya\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg\conninfo.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:\Users\Aditya\Desktop\Aditya\TGbot\dbhelper.py", line 3, in <module>
    conn = psycopg.connect(
  File "C:\Users\Aditya\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg\connection.py", line 561, in connect
    conninfo = make_conninfo(**params)
  File "C:\Users\Aditya\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg\conninfo.py", line 56, in make_conninfo
    _parse_conninfo(conninfo)
  File "C:\Users\Aditya\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg\conninfo.py", line 99, in _parse_conninfo
    raise e.ProgrammingError(str(ex))
psycopg.ProgrammingError: invalid connection option "database"

But when i didnt pass the database argument i didnt get any kind of error... here's my code:

import psycopg 

conn = psycopg.connect(
    host="localhost",
    database="suppliers",
    user="postgres",
    password="pas")

What i am doing wrong here? I am sure that the i have created the database with that name and the password is also correct.

like image 909
Aditya Yadav Avatar asked Jul 17 '26 21:07

Aditya Yadav


1 Answers

You look to be using psycopg3. database was a deprecated parameter in psycopg2 and not allowed in psycopg3. You will need to use dbname per the list here as found in page in the psycopg3 page for connect.