Home > Mobile >  Getting psycopg.ProgrammingError: invalid connection option "database" when pasing databas
Getting psycopg.ProgrammingError: invalid connection option "database" when pasing databas

Time:10-17

Hey when i try to connect to database using psycopg.connect() 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

CodePudding user response:

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.

  • Related