Screen Link: https://app.dataquest.io/m/245/intro-to-postgres/2/connecting-to-postgres
I cannot connect to the Postgres database for this exercise
I tried this
conn = psycopg2.connect("dbname = dq, user = dq")
I got “We could not find any connection to the database.”
OperationalError: FATAL: database "dq," does not exist
If you take a look at the Learn section, or look at the documentation (of which a screenshot you can find below), you’ll see that if you pass the connection details as a string to the method, the
parameter=argument data should be separated by spaces, not commas.
You get the error
OperationalError: FATAL: database "dq," does not exist, because after the command, the parser finds a space and assumes that the database you’re trying to connect to is called
dq), which results in an error because
dq, doesn’t exist.
An alternative, as per the documentation, is to pass several parameters to the method, like so:
conn = psycopg2.connect(dbname = "dq", user = "dq")