Ja - just catch OperationalError exception and check if the code was 1044. Here are a list of all the error codes, so you can choose which ones you want to handle individually:
http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html http://dev.mysql.com/doc/refman/5.5/en/error-messages-client.html Hope this helps Cal On Fri, Oct 14, 2011 at 11:38 AM, Julian Hodgson < [email protected]> wrote: > I've go some python modules which automatically connect to the database > then they are loaded beacuse they have an __init__.py with > > from django.core.management import setup_environ > > import passion.settings > > def loadSettings(): > s = setup_environ(passion.settings) > print s > > # this should only be run from the workbox not on the server > loadSettings() > > This works fine even when it can't connect. > > But later if I do: > > from passion.cg.models import * > users = User.objects.filter( username='julian') > print users > > then I get > > # OperationalError: (1044, "Access denied for user ''@'localhost' to > database 'djangostack'") > # - [line 3] > > So I need a way to test the connection before trying to use the django > models. > > I can just check for exceptions, but is there a better way? > > Julian > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

