簡體   English   中英

@ 密碼和 Airflow postgres 連接失敗

[英]@ in password and Airflow postgres connection is failing

在我的 Postgres 密碼中,airflow.cfg 中有一個 @.Something like dba@123 我已將我的數據庫密碼指定為

#sql_alchemy_conn = postgresql+psycopg2://user:dba@123@postgresserver.com:5432/airflow

拋出錯誤為

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "123@postgresserver.com" to address: Name or service not known

我試圖將密碼指定為 postgresql 的參數

sql_alchemy_conn = postgresql+psycopg2://user:dba@123@postgresserver.com:5432/airflow?password=dba@123

但沒有工作。

誰能幫忙

也許這可以幫助您將數據庫屬性設置為環境變量,然后您可以通過 function 獲取它們,這樣您就不會收到錯誤。

# 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']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM