I am working with heroku postgres for the first time. Did everything according to the tutorial, especially this:
set DATABASE_URL=postgres://$(whoami)
Python:
DATABASE_URL = os.environ['DATABASE_URL']
connection = psycopg2.connect(DATABASE_URL, sslmode='require')
cursor = connection.cursor()
Here is the error message I recieve when I try to connect to the database:
(myenv) C:\deployment\myenv\remastered>heroku local
20:46:58 worker.1 | Traceback (most recent call last):
20:46:58 worker.1 | File "db.py", line 6, in <module>
20:46:58 worker.1 | connection = psycopg2.connect(DATABASE_URL, sslmode='require')
20:46:58 worker.1 | File "C:\deployment\myenv\lib\site-packages\psycopg2\__init__.py", line 122, in connect
20:46:58 worker.1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
20:46:58 worker.1 | psycopg2.OperationalError: could not translate host name "$(whoami)" to address: Unknown server error
[DONE] Killing all processes with signal SIGINT
20:46:58 worker.1 Exited with exit code null
It seems that for some reason it can't translate the "$(whoami)" expression to the database url.
How do I fix this?
Is that supposed to work only when running app on heroku? And when running locally I should specify the url manually?
I get the same error no matter what I inject there instead of $(whoami) unless I copy the url from heroku postgres database credentials for manual connections, but those change periodically so it is not very convinient solution. It connects fine when launching on heroku though.