I have a python function that connects to Azure Postgresql and selects query some rows. In local run without problem. When I published on Azure and run it I received the below error:
OperationalError: (psycopg2.OperationalError) could not translate host name "Mypassword@database_ip" to address
I don't know why to change connection format to db_password@db_ip
, as you see on screenshot.
My function is:
def get_engine(database='db_name', username='username', password='@password', host='ip', port=5432):
engine_string = f"postgresql+psycopg2://{username}:{password}@{host}:{port}/{database}"
engine = sqlalchemy.create_engine(engine_string)
print("Database connection done!")
return engine