Reputation: 81
So I have got this task: You have two abstract reports made available to you on a PostgreSQL server located at: postgres://candidate.company.org/company
username = candidate password = abc
So I used this code to try connect to the database:
import psycopg2 as db
conn = db.connect(host='postgres://candidate.suade.org/company', database='randomname', user='candidate', password='abc', port='5432')
But then i receiver error message:
ProgrammingError: invalid dsn: invalid connection option "username"
As the username give is correct Can anyone help?
Upvotes: 8
Views: 31588
Reputation: 11
Please try with below solution
import psycopg2 as db
conn = db.connect(host='localhost', dbname='randomname', user='candidate', password='abc')
Upvotes: 1
Reputation: 21
if you are using psycopg2
library to connect the Postgres DB , then the connection string should be as mentioned below .
conn = psycopg2.connect(host="localhost",**user = "postgres"**,password = "postgres",database = "postgres") ;
It should be user not username .
Upvotes: 2
Reputation: 75
You are using the wrong parameters. In Postgres you have to use something like this:
conn = pg.DB(host="localhost", user="USERNAME", passwd="PASSWORD", dbname="DBNAME")
That should fix it.
Upvotes: 5