Help req: Problems with MySQLdb

Bruno Desthuilliers onurb at xiludom.gro
Fri Jun 23 05:19:24 EDT 2006


Simon Forman wrote:
> rodmc wrote:
> 
>>Hi,
>>
>>Thanks for your email. Well I am kind of new to exceptions in Python,
>>but here is the code used below, as you can see it is somewhat basic.
>>Is there a way to display more information about the exception?
>>
>>Best,
>>
>>rod
>>
> 
> 
> Use the traceback module (See
> http://docs.python.org/lib/module-traceback.html for info on it.)
> 
> import traceback
> 
> try:
>     db = MySQLdb.connect(host=DBSERVERIP, user="user",
> passwd="password", db="nuke")
> except:
>     print "A database connection error has occurred"

How can you assert it is a database connection error ?

>     traceback.print_exc()
>     return False
> else:
>     pass
> 
> #The rest of the program

You get the same result - with a more accurate error message - by not
handling the exception at all.

> 
> It's generally very difficult to figure out what's going wrong without
> the traceback in front of you.

indeed.


> Also, try an empty string (i.e. "") as your hostname, it's shorthand
> for 'localhost'.
> 
> 
> Hope this helps,
> ~Simon
> 


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list