0

I am using sqlalchemy to upload the dataframe to the AWS RDS Mysql. Below is my code, I would like to display the warnings (Specially for data truncation) as well.

def load_data(translog,input_size):

    try:
        print("Creating connection")

        engine = create_engine("mysql+mysqlconnector://<username>:<pwd>@XXXXXXX.rds.amazonaws.com/XXXX",
                      poolclass=NullPool)

        with engine.connect() as connection:
            translog.to_sql(con=connection,name='transtry',if_exists='append', index=False)
            connection.close()

    except Exception as e:
      #except mysql.connector.Error as error:
        print("Failed to insert record into Transaction table {}".format(e))

    engine.dispose()
    print("MySQL connection is closed")
priya
  • 73
  • 1
  • 1
  • 9

1 Answers1

0

You can use python logger module, it's builtin and set it as stdout output.

Reference: https://docs.python.org/3/howto/logging.html

Md. Mehedi Hasan
  • 196
  • 2
  • 14
  • I tried using the logger but it still doesn't show me the data truncation warnings. I have changed some values in a column to be of length 6, whereas that column has type VARCHAR(5) and still no warning. ```import logging logging.getLogger('sqlalchemy.engine').setLevel(logging.WARNINGS) ``` I have added these 2 code lines in my code. Is there something I am missng to print the errors. The only error shown is when connection is not successfully made. – priya May 12 '21 at 03:34
  • Please follow this link. it might be helpful for you. https://stackoverflow.com/questions/2950385/debugging-displaying-sql-command-sent-to-the-db-by-sqlalchemy – Md. Mehedi Hasan May 12 '21 at 16:40