Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 551417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:23:30+00:00 2026-05-13T11:23:30+00:00

In my python script I would like to trap a Data truncated for column

  • 0

In my python script I would like to trap a “Data truncated for column ‘xxx'” warning durnig my query using MySql.

I saw some posts suggesting the code below, but it doesn’ work.

Do you know if some specific module must be imported or if some option/flag should be called before using this code?

Thanks all

Afeg

import MySQLdb
try:
    cursor.execute(some_statement)
    # code steps always here: No Warning is trapped
    # by the code below
except MySQLdb.Warning, e:
    # handle warnings, if the cursor you're using raises them
except Warning, e:
    # handle warnings, if the cursor you're using raises them
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:23:30+00:00Added an answer on May 13, 2026 at 11:23 am

    Warnings are just that: warnings. They get reported to (usually) stderr, but nothing else is done. You can’t catch them like exceptions because they aren’t being raised.

    You can, however, configure what to do with warnings, and turn them off or turn them into exceptions, using the warnings module. For instance, warnings.filterwarnings('error', category=MySQLdb.Warning) to turn MySQLdb.Warning warnings into exceptions (in which case they would be caught using your try/except) or 'ignore' to not show them at all. You can (and probably should) have more fine-grained filters than just the category.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 541k
  • Answers 541k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Probably has something to do with time zones. You probably… May 17, 2026 at 2:48 am
  • Editorial Team
    Editorial Team added an answer Here's C++03 code which works (for up to 10 template… May 17, 2026 at 2:48 am
  • Editorial Team
    Editorial Team added an answer OK, thanks to the commenter, now a working version. This… May 17, 2026 at 2:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a python script that I would like to add a Shutdown when
I have the following python script and I would like to send fake header
I'm writing a python script which I would like to be able to both
I have a python script which I would like to run at regular intervals.
I would like my python script to search through a directory in SVN, locate
Greetings. I have written a little python script that calls MySQL in a subprocess.
I've been writing python scripts that run locally. I would now like to offer
I have a simple python script that just takes in a filename, and spits
I have an existing python script and I want to wrap it in a
I want to run a Python script from another Python script. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.