[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Cannot catch _mysql_exceptions.OperationalError

Bob Swerdlow

1/18/2008 1:17:00 AM

In our database code (we are using django v0.96) we wanted to catch
and handle MySQL OperationalErrors. We use both the Django models and
database connections.

However, even though we confirmed that a
_mysql_exceptions.OperationalError are raised (particularly 1213
deadlock), we cannot catch them with try/except.

Here's the code that did not work:

import _mysql_exceptions
from _mysql_exceptions import OperationalError

try:
database_code()
except (_mysql_exceptions.OperationalError, OperationalError), e:
error_handling()

Originally, we just had one import, but tried both to ensure that was
not the problem. In debugging, we confirmed that both type(e) and
e.__class_ were <class _mysql_exceptions.OperationalError>.

The only work-around we found was:

try:
database_code()
except Exception, e:
if e.__class__.__name__.find('OperationalError') != -1:
error_handling()
else:
raise

This seems silly. If we used any other exception, the except clause
seems to work correctly.

Is there a problem with _mysql_exceptions.OperationalError? Is there
a better work-around?

Thanks,
Bob


9 Answers

John Nagle

1/18/2008 7:03:00 AM

0

Bob wrote:
> In our database code (we are using django v0.96) we wanted to catch
> and handle MySQL OperationalErrors. We use both the Django models and
> database connections.
>
> However, even though we confirmed that a
> _mysql_exceptions.OperationalError are raised (particularly 1213
> deadlock), we cannot catch them with try/except.

If you're using MySQLdb, it works fine:

try:
... do database operations
except MySQLdb.OperationalError, message: # handle trouble
errorcode = message[0] # get MySQL error code
if errorcode == kmysqlduplicateentry : # if dup on insert
... deal with duplicate entry

If Django has a problem, you'll have to take that up with them.

John Nagle

Jeffrey Froman

1/18/2008 2:27:00 PM

0

Bob wrote:

> Here's the code that did not work:
>
> import _mysql_exceptions
> from _mysql_exceptions import OperationalError
>
> try:
> database_code()
> except (_mysql_exceptions.OperationalError, OperationalError), e:
> error_handling()

Both of the above forms work fine here, as does using
MySQLdb.OperationalError:
------------------------------------------------
>>> import MySQLdb
>>> try:
.... db = MySQLdb.connect(user='jeffrey', host='localhost')
.... except MySQLdb.OperationalError:
.... print 'caught'
....
caught

>>> import _mysql_exceptions
>>> try:
.... db = MySQLdb.connect(user='jeffrey', host='localhost')
.... except _mysql_exceptions.OperationalError:
.... print 'caught'
....
caught

>>> from _mysql_exceptions import OperationalError
>>> try:
.... db = MySQLdb.connect(user='jeffrey', host='localhost')
.... except OperationalError:
.... print 'caught'
....
caught

>>> MySQLdb.OperationalError is _mysql_exceptions.OperationalError
True
>>> MySQLdb.__version__
'1.2.2'
------------------------------------------------


Jeffrey

Brad Greer

6/28/2011 12:43:00 AM

0

On Mon, 27 Jun 2011 13:33:02 -0400, "Schmoe" <schmoe@schmoeville.net>
wrote:

>"Brad Greer" <jjh1102us@yahoo.com> wrote in message
>news:2uce07tub7qvbi2dqhenjov6q6snclutov@4ax.com...
>> On Sun, 26 Jun 2011 05:25:46 -0700 (PDT), yoker <yoker56@yahoo.com>
>> wrote:
>>
>>>
>>>All the Yuengling brews taste much better than any
>>>Budweiser or Miller brew,
>>>in my own worthless (only on rec.music.gdead) opinion.
>>>
>> Barely better than Bud/Miller/Coors. Yuengling is the Saranac of
>> Pennsylvania.
>
>
>Disagree. Yuengling is your icy cold go to beer when too much is too much
>and you don't want the pisswater that Belgium puts out. Love me my
>Yuengling! Good article.

I'm not sure what you're referring to by "when too much is too much"
so it's hard to know how to respond to your post (and I'm completely
baffled by why your choices would be too much or Belgian "pisswater").
Do you mean you find some of the newer west coast beers to be overly
hopped and/or malty? I can understand that, but that still doesn't
mean the only other alternative is Yuengling. There are far better
brewers in Pennsylvania.

Tom

6/29/2011 6:54:00 PM

0

On Jun 26, 9:28 am, Brad Greer <jjh110...@yahoo.com> wrote:
> On Sun, 26 Jun 2011 05:25:46 -0700 (PDT), yoker <yoke...@yahoo.com>
> wrote:
>
>
>
> >All the Yuengling brews taste much better than any
> >Budweiser or Miller brew,
> >in my own worthless (only on rec.music.gdead) opinion.
>
> Barely better than Bud/Miller/Coors.  Yuengling is the Saranac of
> Pennsylvania.

the have done a good job marketing it.to me its an average beer yeah
I'll take it over bud & miller but thats not saying much.remember when
you couldn't get coors east of the miss. in the 60s/70s.all you heard
about was this great beer from the rockies that wouldn't ship
unrefridgerated due to its pride in taking care of its product.it
built an image that really didn't hold up after you tasted it.sure
better than bud(must be something bad in beechwood)but anothe pale
american lager with no real taste.my opinion is worthless too, just
that an opinion.just had a victory prima pils for some real pils taste

Brad Greer

6/29/2011 10:58:00 PM

0

On Wed, 29 Jun 2011 11:54:28 -0700 (PDT), Tom <tomfrenchu@gmail.com>
wrote:

>On Jun 26, 9:28?am, Brad Greer <jjh110...@yahoo.com> wrote:
>> On Sun, 26 Jun 2011 05:25:46 -0700 (PDT), yoker <yoke...@yahoo.com>
>> wrote:
>>
>>
>>
>> >All the Yuengling brews taste much better than any
>> >Budweiser or Miller brew,
>> >in my own worthless (only on rec.music.gdead) opinion.
>>
>> Barely better than Bud/Miller/Coors. ?Yuengling is the Saranac of
>> Pennsylvania.
>
>the have done a good job marketing it.to me its an average beer yeah
>I'll take it over bud & miller but thats not saying much.remember when
>you couldn't get coors east of the miss. in the 60s/70s.all you heard
>about was this great beer from the rockies that wouldn't ship
>unrefridgerated due to its pride in taking care of its product.it
>built an image that really didn't hold up after you tasted it.sure
>better than bud(must be something bad in beechwood)but anothe pale
>american lager with no real taste.my opinion is worthless too, just
>that an opinion.just had a victory prima pils for some real pils taste

Ah, now Victory is the king of Pennsylvania breweries. I don't know
that I've ever had a bad beer from them.

Lonesome Mike

6/30/2011 12:04:00 AM

0

Brad Greer <jjh1102us@yahoo.com> wrote in
news:jebn075bjas19j9dkbgmgbv0j5tn6imq89@4ax.com:

> On Wed, 29 Jun 2011 11:54:28 -0700 (PDT), Tom <tomfrenchu@gmail.com>
> wrote:
>
>>On Jun 26, 9:28?am, Brad Greer <jjh110...@yahoo.com> wrote:
>>> On Sun, 26 Jun 2011 05:25:46 -0700 (PDT), yoker <yoke...@yahoo.com>
>>> wrote:
>>>
>>>
>>>
>>> >All the Yuengling brews taste much better than any
>>> >Budweiser or Miller brew,
>>> >in my own worthless (only on rec.music.gdead) opinion.
>>>
>>> Barely better than Bud/Miller/Coors. ?Yuengling is the Saranac of
>>> Pennsylvania.
>>
>>the have done a good job marketing it.to me its an average beer yeah
>>I'll take it over bud & miller but thats not saying much.remember when
>>you couldn't get coors east of the miss. in the 60s/70s.all you heard
>>about was this great beer from the rockies that wouldn't ship
>>unrefridgerated due to its pride in taking care of its product.it
>>built an image that really didn't hold up after you tasted it.sure
>>better than bud(must be something bad in beechwood)but anothe pale
>>american lager with no real taste.my opinion is worthless too, just
>>that an opinion.just had a victory prima pils for some real pils taste
>
> Ah, now Victory is the king of Pennsylvania breweries. I don't know
> that I've ever had a bad beer from them.
>

When I was growing up in Eastern Pennsylvania we drank Rolling Rock because
it was cheap. Imagine my surprise when I moved out to SoCal and found the
local beach taverns selling RR as a premium beer. Now that is some good
marketing. I'll still have one once in awhile when I want light and crisp
but I'd just assume have a PBR.

mike

Neil X

6/30/2011 4:08:00 AM

0

On Jun 26, 9:28 am, Brad Greer <jjh110...@yahoo.com> wrote:
> On Sun, 26 Jun 2011 05:25:46 -0700 (PDT), yoker <yoke...@yahoo.com>
> wrote:
>
>
>
> >All the Yuengling brews taste much better than any
> >Budweiser or Miller brew,
> >in my own worthless (only on rec.music.gdead) opinion.
>
> Barely better than Bud/Miller/Coors.  Yuengling is the Saranac of
> Pennsylvania.


Don't insult Saranac. Not that insulting Saranac isn't a worthy
endeavor.

Yuengling is barely better as a "nouvelle microbrew" than it was when
it was just pure, plain, honest piss.

Peace,
Neil X.

band beyond description

6/30/2011 6:18:00 PM

0

On 2011-06-30 00:07:38 -0400, Neil X <neilxk@yahoo.com> said:

> On Jun 26, 9:28??am, Brad Greer <jjh110...@yahoo.com> wrote:
>> On Sun, 26 Jun 2011 05:25:46 -0700 (PDT), yoker <yoke...@yahoo.com>
>> wrote:
>>
>>
>>
>>> All the Yuengling brews taste much better than any
>>> Budweiser or Miller brew,
>>> in my own worthless (only on rec.music.gdead) opinion.
>>
>> Barely better than Bud/Miller/Coors. ??Yuengling is the Saranac of
>> Pennsylvania.
>
>
> Don't insult Saranac. Not that insulting Saranac isn't a worthy
> endeavor.

anything that gets The Old Geezer to come outta hibernation can't be all bad!

>
> Yuengling is barely better as a "nouvelle microbrew" than it was when
> it was just pure, plain, honest piss.
>
> Peace,
> Neil X.


thanks for the tip! I therefore shan't be picking any up whilst on my
U.S. soujourn...
--
Peace,
Steve

mjd

7/1/2011 12:28:00 AM

0

On Jun 26, 9:28 am, Brad Greer <jjh110...@yahoo.com> wrote:
> On Sun, 26 Jun 2011 05:25:46 -0700 (PDT), yoker <yoke...@yahoo.com>
> wrote:
>
>
>
> >All the Yuengling brews taste much better than any
> >Budweiser or Miller brew,
> >in my own worthless (only on rec.music.gdead) opinion.
>
> Barely better than Bud/Miller/Coors.  Yuengling is the Saranac of
> Pennsylvania.

all due respect brad, but beer snobs were better in the seventies.
yuenglings is the shit, though as an addict I may be a bit biased.

thanks yoker for posting. visit the brewery it's a trip back in time!