traceback and mySQL
JXStern
JXSternChangeX2R at gte.net
Thu Oct 10 00:03:39 EDT 2002
Cuz that's the error message, dummy, not the walkback.
It's available in ss.exc_info()[0:1]
J.
On Wed, 09 Oct 2002 02:32:32 GMT, JXStern <JXSternChangeX2R at gte.net>
wrote:
>Why does
>
> traceback.print_exc()
>
>capture the excellent mySQL error message:
>
> ProgrammingError: (1064, "You have an error in your SQL syntax
>near 'eat my shorts' at line 1")
>
>but
> traceback.extract_tb(sys.exc_info()[2])
>
>does not list it?
>
>I want to capture all into a list for processing.
>
>I've tried some other variations without success.
>
>Thanks!
>
>Still a Python newbie,
> (or I guess I would dive into the source)
>Joshua Stern
>
>
>
>--------- source -----------
>
>import os, sys
>import traceback
>import MySQLdb
>
>db = MySQLdb.connect(host="localhost", user="root", db="HMon")
>cx = db.cursor()
>
>print "connected to database, got cursor, try exception"
>
>try:
> cx.execute("eat my shorts")
>except:
> print "***in exception handler"
> print sys.exc_info()
> s = raw_input("->")
>
> tb = traceback.extract_tb(sys.exc_info()[2])
>
> traceback.print_exc()
>
> s = raw_input("->")
> print tb
>
>cx.close()
>cx = None
>db.close()
>db = None
>
>--------- output follows -----------
>
>connected to database, got cursor, try exception
>***in exception handler
>(<class _mysql_exceptions.ProgrammingError at 0x00AF7DB0>,
><_mysql_exceptions.ProgrammingError instance at 0x0163C068>,
><traceback object at 0x0163DDB8>)
>->
>Traceback (most recent call last):
> File "C:/Hax/HMon/dbclasses/foo3.py", line 40, in ?
> cx.execute("eat my shorts")
> File "C:\PROGRA~1\Python22\Lib\site-packages\MySQLdb\cursors.py",
>line 95, in execute
> return self._execute(query, args)
> File "C:\PROGRA~1\Python22\Lib\site-packages\MySQLdb\cursors.py",
>line 114, in _execute
> self.errorhandler(self, exc, value)
> File
>"C:\PROGRA~1\Python22\Lib\site-packages\MySQLdb\connections.py", line
>33, in defaulterrorhandler
> raise errorclass, errorvalue
>ProgrammingError: (1064, "You have an error in your SQL syntax near
>'eat my shorts' at line 1")
>->
>[('C:/Hax/HMon/dbclasses/foo3.py', 40, '?', 'cx.execute("eat my
>shorts")'),
>('C:\\PROGRA~1\\Python22\\Lib\\site-packages\\MySQLdb\\cursors.py',
>95, 'execute', 'return self._execute(query, args)'),
>('C:\\PROGRA~1\\Python22\\Lib\\site-packages\\MySQLdb\\cursors.py',
>114, '_execute', 'self.errorhandler(self, exc, value)'),
>('C:\\PROGRA~1\\Python22\\Lib\\site-packages\\MySQLdb\\connections.py',
>33, 'defaulterrorhandler', 'raise errorclass, errorvalue')]
More information about the Python-list
mailing list