Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: MySQL Error

0 views
Skip to first unread message

Carsten Haese

unread,
Jan 1, 2010, 12:04:10 PM1/1/10
to pytho...@python.org
Victor Subervi wrote:
> However, "ProgrammingError" is not an error. How do I discover the real
> error, so I can write the appropriate except statement?

You're not making any sense. How did you determine that ProgrammingError
is not an error or that it's not the "real error"? Show us the code you
ran, the output you expected, and the output it produced instead.

Blind guess: You're using "except ProgrammingError" when you should be
using "except MySQLdb.ProgrammingError". If this guess is incorrect, see
above.

--
Carsten Haese
http://informixdb.sourceforge.net

MRAB

unread,
Jan 1, 2010, 12:10:02 PM1/1/10
to python-list
Victor Subervi wrote:
> Hi;
> I'm trying to avoid the mortal sin of blank excepts. I intentionally
> threw this error:
>
> Traceback (most recent call last):
> File "/var/www/html/angrynates.com/cart/createAssociations2.py
> <http://angrynates.com/cart/createAssociations2.py>", line 137, in ?
> createAssociations2()
> File "/var/www/html/angrynates.com/cart/createAssociations2.py
> <http://angrynates.com/cart/createAssociations2.py>", line 108, in
> createAssociations2
> cursor.execute(sql)
> File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line
> 163, in execute
> self.errorhandler(self, exc, value)
> File "/usr/lib64/python2.4/site-packages/MySQLdb/connections.py", line
> 35, in defaulterrorhandler
> raise errorclass, errorvalue
> ProgrammingError: (1146, "Table 'test.productsAssociations' doesn't exist")

>
> However, "ProgrammingError" is not an error. How do I discover the real
> error, so I can write the appropriate except statement?
>
What makes you think it isn't?

As the traceback says, "Table 'test.productsAssociations' doesn't
exist", and that's the cause.

Benjamin Kaplan

unread,
Jan 1, 2010, 2:04:34 PM1/1/10
to pytho...@python.org
On Fri, Jan 1, 2010 at 1:32 PM, Victor Subervi <victor...@gmail.com> wrote:
> Because I've tried
> except ProgrammingError:
>   pass
> before and *that* threw an error. So I didnt' try again.
> beno

Just because it's not in the current namespace doesn't mean it's not
an error. From PEP 249 (the db api v2) :

ProgrammingError

Exception raised for programming errors, e.g. table not
found or already exists, syntax error in the SQL
statement, wrong number of parameters specified, etc. It
must be a subclass of DatabaseError.

>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>

MRAB

unread,
Jan 1, 2010, 3:24:09 PM1/1/10
to pytho...@python.org
You shouldn't just that it threw an error and give up, you should look
at what the error was, in this case a NameError, which means that it
doesn't know that name. Why? Because it's defined in the MySQL module
that you imported, but you didn't import the name ProgrammingError.
0 new messages