1

I am setting a fastAPI, and I have a postgresql database I want to connect it to. I am following a this guide to do so, and I am finding some errors when trying to set the DATABASE_URL.

My end goal is to perform a SQL query to such database, and then later, deploy the application to Heroku where I should connect it to the postgresql database stored there.

host_server = os.environ.get('host_server', 'localhost')
db_server_port = urllib.parse.quote_plus(str(os.environ.get('db_server_port', '5432')))
database_name = os.environ.get('nameofmydatabase', 'fastapi')
db_username = urllib.parse.quote_plus(str(os.environ.get('myusername', 'postgres')))
db_password = urllib.parse.quote_plus(str(os.environ.get('mypassword123', 'secret')))
ssl_mode = urllib.parse.quote_plus(str(os.environ.get('ssl_mode','prefer')))
DATABASE_URL = 'postgresql://{}:{}@{}:{}/{}?sslmode={}'.format(db_username, db_password, host_server, db_server_port, database_name, ssl_mode)

With that configuration I am getting

    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL:  role "postgres" does not exist

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Gotey
  • 449
  • 4
  • 15
  • 41

0 Answers0