'@ in password and Airflow postgres connection is failing

In my Postgres password , there is a @ .Something like dba@123 in the airflow.cfg I have specified my DB password as

#sql_alchemy_conn = postgresql+psycopg2://user:dba@[email protected]:5432/airflow

throwing error as

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "[email protected]" to address: Name or service not known

I tried to specify the password as parameters to the postgresql

sql_alchemy_conn = postgresql+psycopg2://user:dba@[email protected]:5432/airflow?password=dba@123

but not working .

Can any one help



Solution 1:[1]

Maybe this can help you can set the DB properties as an Environment variable and then you can get them via function, like this you will not get an error.

# def db_props():

#     db_config = {
#         'host': os.environ["_HOST"],
#         'port': os.environ["_PORT"],
#         'db': os.environ["_DATABASE"],
#         'username': os.environ["_USERNAME"],
#         'password': os.environ["_PASSWORD"]

#     }

#     return db_config




and later in code, you can do this while making a connection 

    db_config = db_props()

    server = db_config['host']
    port = db_config['port']
    database = db_config['db']
    username = db_config["username"]
    password = db_config['password']

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kaolin