I’m doing some experiments with airflow dags in docker container, and want to have a function that returns a db connection and cursor.
def db_connect():
try:
conn = pymysql.connect(
host=CONFIG.get("db_host"),
port=CONFIG.get("db_port"),
user=CONFIG.get("db_user"),
password=CONFIG.get("db_password"),
)
logger.info(
"Database connection established: %(info)s"
% {
"info": conn.get_host_info(),
}
)
cursor = conn.cursor()
return conn, cursor
except Exception as e:
logger.error(
"Failed to connect to database: %(error)s"
% {
"error": e,
}
)
raise AirflowException("Database connection failed")
error:
TypeError: Object of type tuple is not JSON serializable
I have tried the exact same code in the local environment and it works fine.
New contributor
Bamboo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.